[Bug report] Unrecognised JPEG File from Gallery on Android
Opened this issue · 6 comments
Version
2.1.2
Platforms
Android
Device Model
Samsung Galaxy A10
flutter info
$ flutter doctor -v
[√] Flutter (Channel stable, 3.13.9, on Microsoft Windows [version 10.0.22621.2428], locale fr-FR)
• Flutter version 3.13.9 on channel stable at C:\Users\pnv_fch.NUC_PNV_FCH\fvm\versions\3.13.3
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision d211f42860 (3 weeks ago), 2023-10-25 13:42:25 -0700
• Engine revision 0545f8705d
• Dart version 3.1.5
• DevTools version 2.25.0
[√] Windows Version (Installed version of Windows is version 10 or higher)
[!] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
• Android SDK at C:\Users\pnv_fch\AppData\Local\Android\Sdk
X cmdline-tools component is missing
Run `path/to/sdkmanager --install "cmdline-tools;latest"`
See https://developer.android.com/studio/command-line for more details.
X Android license status unknown.
Run `flutter doctor --android-licenses` to accept the SDK licenses.
See https://flutter.dev/docs/get-started/install/windows#android-setup for more details.
[√] Chrome - develop for the web
• Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe
[√] Visual Studio - develop Windows apps (Visual Studio Enterprise 2022 17.6.5)
• Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Enterprise
• Visual Studio Enterprise 2022 version 17.6.33829.357
• Windows 10 SDK version 10.0.22000.0
[√] Android Studio (version 2022.3)
• Android Studio at C:\Program Files\Android\Android Studio
• 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.6+0-b2043.56-10027231)
[√] Connected device (3 available)
• SM A105FN (mobile) • R58N30FEYRV • android-arm • Android 11 (API 30)
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [version 10.0.22621.2428]
• Chrome (web) • chrome • web-javascript • Google Chrome 118.0.5993.89
[√] Network resources
• All expected network resources are available.
! Doctor found issues in 1 category.
How to reproduce?
- Take a picture with the phone's camera
- Call the method
getSize
on the produced file
When i tried doing that, an exception was thrown by lib/src/image_size_getter.dart:123
112 static Size getSize(ImageInput input) {
113 if (!input.exists()) {
114 throw StateError('The input is not exists.');
115 }
116
117 for (var value in _decoders) {
118 if (value.isValid(input)) {
119 return value.getSize(input);
120 }
121 }
122
123 throw UnsupportedError('The input is not supported.');
124 }
Of couse that means that the condition value.isValid(input)
evaluated to false for decoders, but the specific problem here is that the isValid
from the JPEG decoder returned false.
I looked into why the JPEG decoder doesn't recognise the file as proper JPEG, and found out that the file I tested with has a valid header, but the footer check failed.
I then inspected how the footer check was written, found out that you expect to find the two bytes 0xFF, 0xD9 at the very end of the file. On the file I tested with, the two last bytes are 0x46, 0x54 (ascii F, ascii T). So this is why the footer check failed.
But this file should be valid JPEG, since (firstly it ends with .jpg), my phone can render it, and Flutter's Image
renders it well, too.
So I did some research, learnt the basics of JPEG markers, and that the 0xFF 0xD9 marker is not the "End of JPEG file" marker. It is the "End of Image" marker (EOI for short), meaning that a valid JPEG file can contain data after this EOI marker; thus it is not mandatory for a JPEG file to end with 0xFF 0xD9.
I then checked by hand, and the picture I tested with does contain this EOI marker, a few tens of bytes before the end of file.
Here is a link to the picture I tested with, if it helps you testing.
Logs
════════ Exception caught by widgets library ═══════════════════════════════════
The following UnsupportedError was thrown building KeyedSubtree-[GlobalKey#cc1b6]:
Unsupported operation: The input is not supported.
I guess the picture may be a motion photo.
I'll try to fix it.
hi, same problem
hi @CaiJingLong did you have any suggestions for this case?
I am facing the same issue
same issue. any idea?
same issue. jpg picture