Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug report] Hashing image before and after compressWithFile results diff depending on the format #313

Open
raulmabe-labhouse opened this issue Jul 22, 2024 · 0 comments

Comments

@raulmabe-labhouse
Copy link

Version

2.3.0

Platforms

dart

Device Model

iPhone 13

flutter info

[✓] Flutter (Channel stable, 3.22.1, on macOS 14.5 23F79 darwin-arm64, locale en-ES)
    • Flutter version 3.22.1 on channel stable at /Users/raulmateo/fvm/versions/3.22.1
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision a14f74ff3a (9 weeks ago), 2024-05-22 11:08:21 -0500
    • Engine revision 55eae6864b
    • Dart version 3.4.1
    • DevTools version 2.34.3

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at /Users/raulmateo/Library/Android/sdk
    • Platform android-34, build-tools 33.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15C65
    • CocoaPods version 1.15.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.10+0-17.0.10b1087.21-11572160)

[✓] VS Code (version 1.91.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.92.0

[✓] Connected device (3 available)
    • macOS (desktop)                 • macos                 • darwin-arm64   • macOS 14.5 23F79 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin         • macOS 14.5 23F79 darwin-arm64
    • Chrome (web)                    • chrome                • web-javascript • Google Chrome 126.0.6478.183

[✓] Network resources
    • All expected network resources are available.

• No issues found!

How to reproduce?

Import crypto package.

  1. Use sha256 to convert image to hash.
  2. Call the compressWithFile method with PNG.
  3. Use sha256 to hash the resulting image again
  4. Test that the first hash and the second hash are the same.

Now do the same with WEBP, and you'll see the hashes are different.

Logs

No response

Example code (optional)

Future<String> removeExif(String path) async {
    final bytes = await FlutterImageCompress.compressWithFile(path, quality: 100, format: CompressFormat.png);
    final newPath = await FilesMixin.getNewTempPath('tmp', 'png');
    File(newPath).writeAsBytesSync(bytes!);
    return newPath;
  }

  Future<String> generateUniqueImageHash(File file) async {
    final digest = await sha256.bind(file.openRead()).first;
    return digest.toString();
  }

Contact

raul.mateo@labhouse.io

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant