Repository: flutter
Issue: Image.errorBuilder throws exception for invalid image data
Labels: framework,a: images,a: error message,has reproducible steps,P2,found in release: 3.0,found in release: 3.1,team-framework,triaged-framework

<!-- Thank you for using Flutter!

     If you are looking for support, please check out our documentation
     or consider asking a question on Stack Overflow:
      * https://flutter.dev/
      * https://api.flutter.dev/
      * https://stackoverflow.com/questions/tagged/flutter?sort=frequent

     If you have found a bug or if our documentation doesn't have an answer
     to what you're looking for, then fill out the template below. Please read
     our guide to filing a bug first: https://flutter.dev/docs/resources/bug-reports
-->

## Steps to Reproduce

<!-- Please include full steps to reproduce so that we can reproduce the problem. -->

1. Create a new flutter project and use [this gist](https://dartpad.dev/?id=e6337b7c2fdf316c0ee7293a0654d2c5) as the `main.dart`
2. Compile and run on Android or iOS

**Expected results:** The image should not load (as the image data is invalid) and the `errorBuilder` should be called instead.

**Actual results:** App crashes with uncaught exception `_Exception (Exception: Invalid image data)`
```
D/skia    (27874): libjpeg error 68 <Unsupported marker type 0x73> from output_message
D/skia    (27874): libjpeg error 68 <Unsupported marker type 0x73> from ReadHeader
E/FlutterJNI(27874): Failed to decode image
E/FlutterJNI(27874): android.graphics.ImageDecoder$DecodeException: Failed to create image decoder with message 'invalid input'Input contained an error.
E/FlutterJNI(27874): 	at android.graphics.ImageDecoder.nCreate(Native Method)
E/FlutterJNI(27874): 	at android.graphics.ImageDecoder.access$200(ImageDecoder.java:173)
E/FlutterJNI(27874): 	at android.graphics.ImageDecoder$ByteBufferSource.createImageDecoder(ImageDecoder.java:250)
E/FlutterJNI(27874): 	at android.graphics.ImageDecoder.decodeBitmapImpl(ImageDecoder.java:1847)
E/FlutterJNI(27874): 	at android.graphics.ImageDecoder.decodeBitmap(ImageDecoder.java:1840)
E/FlutterJNI(27874): 	at io.flutter.embedding.engine.FlutterJNI.decodeImage(FlutterJNI.java:524)
I/ample.img_cras(27874): ProcessProfilingInfo new_methods=851 is saved saved_to_disk=1 resolve_classes_delay=8000
```
```
_futurize (dart:ui/painting.dart:5718)
ImageDescriptor.encoded (dart:ui/painting.dart:5574)
instantiateImageCodec (dart:ui/painting.dart:2056)
<asynchronous gap> (Unknown Source:0)
```

<details>
<summary>Code sample</summary>
See gist linked above. Minimal usage is:

```dart
Image(
        image: invalidJpgImageData,
        width: 640,
        height: 480,
        gaplessPlayback: true
      )
```

For obtaining an invalid JPEG, use the bytes in the gist or open a JPEG in a hex editor and keep changing bytes until a viewer can no longer open it properly.
</details>

<details>
  <summary>Logs</summary>

<!--
      Run your application with `flutter run --verbose` and attach all the
      log output below between the lines with the backticks. If there is an
      exception, please see if the error message includes enough information
      to explain how to solve the issue. If there is a crash, please include
      the entirety of the crash log including the backtrace.
-->

```
[  +49 ms] executing: uname -m
[  +21 ms] Exit code 0 from: uname -m
[        ] x86_64
[   +4 ms] executing: [/home/sgehring/.asdf/installs/flutter/3.0.1-stable/] git -c log.showSignature=false log -n 1 --pretty=format:%H
[   +2 ms] Exit code 0 from: git -c log.showSignature=false log -n 1 --pretty=format:%H
[        ] fb57da5f945d02ef4f98dfd9409a72b7cce74268
[        ] executing: [/home/sgehring/.asdf/installs/flutter/3.0.1-stable/] git tag --points-at fb57da5f945d02ef4f98dfd9409a72b7cce74268
[   +7 ms] Exit code 0 from: git tag --points-at fb57da5f945d02ef4f98dfd9409a72b7cce74268
[        ] 3.0.1
[   +5 ms] executing: [/home/sgehring/.asdf/installs/flutter/3.0.1-stable/] git rev-parse --abbrev-ref --symbolic @{u}
[   +2 ms] Exit code 0 from: git rev-parse --abbrev-ref --symbolic @{u}
[        ] origin/stable
[        ] executing: [/home/sgehring/.asdf/installs/flutter/3.0.1-stable/] git ls-remote --get-url origin
[   +1 ms] Exit code 0 from: git ls-remote --get-url origin
[        ] https://github.com/flutter/flutter.git
[  +55 ms] executing: [/home/sgehring/.asdf/installs/flutter/3.0.1-stable/] git rev-parse --abbrev-ref HEAD
[   +2 ms] Exit code 0 from: git rev-parse --abbrev-ref HEAD
[        ] stable
[  +35 ms] Artifact Instance of 'AndroidGenSnapshotArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterWebSdk' is not required, skipping update.
[   +1 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'WindowsUwpEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[  +42 ms] executing: /home/sgehring/Android/Sdk/platform-tools/adb devices -l
[  +23 ms] List of devices attached
           802d5cf6               device usb:1-4 product:beryllium model:POCOPHONE_F1 device:beryllium transport_id:2
[   +4 ms] /home/sgehring/Android/Sdk/platform-tools/adb -s 802d5cf6 shell getprop
[  +91 ms] Artifact Instance of 'AndroidInternalBuildArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'IOSEngineArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'WindowsEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'WindowsUwpEngineArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSEngineArtifacts' is not required, skipping update.
[   +1 ms] Artifact Instance of 'LinuxFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'MacOSFuchsiaSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerSDKArtifacts' is not required, skipping update.
[        ] Artifact Instance of 'FlutterRunnerDebugSymbols' is not required, skipping update.
[  +82 ms] Skipping pub get: version match.
[  +44 ms] Generating /home/sgehring/development/img_crash/android/app/src/main/java/io/flutter/plugins/GeneratedPluginRegistrant.java
[  +43 ms] ro.hardware = qcom
[  +29 ms] Initializing file store
[   +7 ms] Skipping target: gen_localizations
[   +4 ms] gen_dart_plugin_registrant: Starting due to {InvalidatedReasonKind.inputChanged: The following inputs have updated contents: /home/sgehring/development/img_crash/.dart_tool/package_config_subset}
[  +16 ms] gen_dart_plugin_registrant: Complete
[        ] Skipping target: _composite
[   +1 ms] complete
[   +4 ms] Launching lib/main.dart on POCOPHONE F1 in debug mode...
[   +3 ms] /home/sgehring/.asdf/installs/flutter/3.0.1-stable/bin/cache/dart-sdk/bin/dart --disable-dart-dev /home/sgehring/.asdf/installs/flutter/3.0.1-stable/bin/cache/dart-sdk/bin/snapshots/frontend_server.dart.snapshot --sdk-root /home/sgehring/.asdf/installs/flutter/3.0.1-stable/bin/cache/artifacts/engine/common/flutter_patched_sdk/ --incremental --target=flutter --debugger-module-names --experimental-emit-debug-metadata -DFLUTTER_WEB_AUTO_DETECT=true --output-dill /tmp/flutter_tools.OMYSCH/flutter_tool.RGHECU/app.dill --packages /home/sgehring/development/img_crash/.dart_tool/package_config.json -Ddart.vm.profile=false -Ddart.vm.product=false --enable-asserts --track-widget-creation --filesystem-scheme org-dartlang-root --initialize-from-dill build/c075001b96339384a97db4862b8ab8db.cache.dill.track.dill --enable-experiment=alternative-invalidation-strategy
[   +4 ms] executing: /home/sgehring/Android/Sdk/build-tools/32.0.0/aapt dump xmltree /home/sgehring/development/img_crash/build/app/outputs/flutter-apk/app.apk AndroidManifest.xml
[   +2 ms] Exit code 0 from: /home/sgehring/Android/Sdk/build-tools/32.0.0/aapt dump xmltree /home/sgehring/development/img_crash/build/app/outputs/flutter-apk/app.apk AndroidManifest.xml
[        ] N: android=http://schemas.android.com/apk/res/android
             E: manifest (line=2)
               A: android:versionCode(0x0101021b)=(type 0x10)0x1
               A: android:versionName(0x0101021c)="1.0.0" (Raw: "1.0.0")
               A: android:compileSdkVersion(0x01010572)=(type 0x10)0x1f
               A: android:compileSdkVersionCodename(0x01010573)="12" (Raw: "12")
               A: package="com.example.img_crash" (Raw: "com.example.img_crash")
               A: platformBuildVersionCode=(type 0x10)0x1f
               A: platformBuildVersionName=(type 0x10)0xc
               E: uses-sdk (line=7)
                 A: android:minSdkVersion(0x0101020c)=(type 0x10)0x10
                 A: android:targetSdkVersion(0x01010270)=(type 0x10)0x1f
               E: uses-permission (line=15)
                 A: android:name(0x01010003)="android.permission.INTERNET" (Raw: "android.permission.INTERNET")
               E: application (line=17)
                 A: android:label(0x01010001)="img_crash" (Raw: "img_crash")
                 A: android:icon(0x01010002)=@0x7f080000
                 A: android:name(0x01010003)="android.app.Application" (Raw: "android.app.Application")
                 A: android:debuggable(0x0101000f)=(type 0x12)0xffffffff
                 A: android:appComponentFactory(0x0101057a)="androidx.core.app.CoreComponentFactory" (Raw: "androidx.core.app.CoreComponentFactory")
                 E: activity (line=23)
                   A: android:theme(0x01010000)=@0x7f0a0000
                   A: android:name(0x01010003)="com.example.img_crash.MainActivity" (Raw: "com.example.img_crash.MainActivity")
                   A: android:exported(0x01010010)=(type 0x12)0xffffffff
                   A: android:launchMode(0x0101001d)=(type 0x10)0x1
                   A: android:configChanges(0x0101001f)=(type 0x11)0x40003fb4
                   A: android:windowSoftInputMode(0x0101022b)=(type 0x11)0x10
                   A: android:hardwareAccelerated(0x010102d3)=(type 0x12)0xffffffff
                   E: meta-data (line=38)
                     A: android:name(0x01010003)="io.flutter.embedding.android.NormalTheme" (Raw: "io.flutter.embedding.android.NormalTheme")
                     A: android:resource(0x01010025)=@0x7f0a0001
                   E: intent-filter (line=42)
                     E: action (line=43)
                       A: android:name(0x01010003)="android.intent.action.MAIN" (Raw: "android.intent.action.MAIN")
                     E: category (line=45)
                       A: android:name(0x01010003)="android.intent.category.LAUNCHER" (Raw: "android.intent.category.LAUNCHER")
                 E: meta-data (line=52)
                   A: android:name(0x01010003)="flutterEmbedding" (Raw: "flutterEmbedding")
                   A: android:value(0x01010024)=(type 0x10)0x2
                 E: uses-library (line=56)
                   A: android:name(0x01010003)="androidx.window.extensions" (Raw: "androidx.window.extensions")
                   A: android:required(0x0101028e)=(type 0x12)0x0
                 E: uses-library (line=59)
                   A: android:name(0x01010003)="androidx.window.sidecar" (Raw: "androidx.window.sidecar")
                   A: android:required(0x0101028e)=(type 0x12)0x0
[   +4 ms] executing: /home/sgehring/Android/Sdk/platform-tools/adb -s 802d5cf6 shell -x logcat -v time -t 1
[   +9 ms] <- compile package:img_crash/main.dart
[ +115 ms] --------- beginning of main
           07-11 18:12:29.456 E/libc    (  886): Access denied finding property "ro.hardware.fp.sideCap"
[   +5 ms] executing: /home/sgehring/Android/Sdk/platform-tools/adb version
[   +2 ms] Android Debug Bridge version 1.0.41
           Version 31.0.3-7562133
           Installed as /home/sgehring/Android/Sdk/platform-tools/adb
[   +1 ms] executing: /home/sgehring/Android/Sdk/platform-tools/adb start-server
[   +2 ms] Building APK
[  +10 ms] Running Gradle task 'assembleDebug'...
[   +1 ms] Using gradle from /home/sgehring/development/img_crash/android/gradlew.
[  +11 ms] executing: /opt/android-studio/jre/bin/java -version
[  +84 ms] Exit code 0 from: /opt/android-studio/jre/bin/java -version
[        ] openjdk version "11.0.12" 2021-07-20
           OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
           OpenJDK 64-Bit Server VM (build 11.0.12+0-b1504.28-7817840, mixed mode)
[        ] executing: /opt/android-studio/jre/bin/java -version
[  +83 ms] Exit code 0 from: /opt/android-studio/jre/bin/java -version
[        ] openjdk version "11.0.12" 2021-07-20
           OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
           OpenJDK 64-Bit Server VM (build 11.0.12+0-b1504.28-7817840, mixed mode)
[   +1 ms] executing: [/home/sgehring/development/img_crash/android/] /home/sgehring/development/img_crash/android/gradlew -Pverbose=true -Ptarget-platform=android-arm64 -Ptarget=/home/sgehring/development/img_crash/lib/main.dart -Pbase-application-name=android.app.Application -Pdart-defines=RkxVVFRFUl9XRUJfQVVUT19ERVRFQ1Q9dHJ1ZQ== -Pdart-obfuscation=false -Ptrack-widget-creation=true -Ptree-shake-icons=false -Pfilesystem-scheme=org-dartlang-root assembleDebug
[ +696 ms] > Task :app:preBuild UP-TO-DATE
[        ] > Task :app:preDebugBuild UP-TO-DATE
[        ] > Task :app:mergeDebugNativeDebugMetadata NO-SOURCE
[  +94 ms] > Task :app:compileFlutterBuildDebug UP-TO-DATE
[        ] > Task :app:packLibsflutterBuildDebug UP-TO-DATE
[        ] > Task :app:compileDebugAidl NO-SOURCE
[        ] > Task :app:compileDebugRenderscript NO-SOURCE
[        ] > Task :app:generateDebugBuildConfig UP-TO-DATE
[        ] > Task :app:checkDebugAarMetadata UP-TO-DATE
[        ] > Task :app:cleanMergeDebugAssets
[        ] > Task :app:mergeDebugShaders UP-TO-DATE
[        ] > Task :app:compileDebugShaders NO-SOURCE
[        ] > Task :app:generateDebugAssets UP-TO-DATE
[        ] > Task :app:mergeDebugAssets
[ +198 ms] > Task :app:copyFlutterAssetsDebug
[        ] > Task :app:generateDebugResValues UP-TO-DATE
[        ] > Task :app:generateDebugResources UP-TO-DATE
[        ] > Task :app:mergeDebugResources UP-TO-DATE
[        ] > Task :app:createDebugCompatibleScreenManifests UP-TO-DATE
[        ] > Task :app:extractDeepLinksDebug UP-TO-DATE
[        ] > Task :app:processDebugMainManifest UP-TO-DATE
[        ] > Task :app:processDebugManifest UP-TO-DATE
[        ] > Task :app:processDebugManifestForPackage UP-TO-DATE
[        ] > Task :app:processDebugResources UP-TO-DATE
[        ] > Task :app:compileDebugKotlin UP-TO-DATE
[        ] > Task :app:javaPreCompileDebug UP-TO-DATE
[        ] > Task :app:compileDebugJavaWithJavac UP-TO-DATE
[        ] > Task :app:processDebugJavaRes NO-SOURCE
[  +98 ms] > Task :app:mergeDebugJavaResource UP-TO-DATE
[        ] > Task :app:checkDebugDuplicateClasses UP-TO-DATE
[        ] > Task :app:dexBuilderDebug UP-TO-DATE
[        ] > Task :app:desugarDebugFileDependencies UP-TO-DATE
[        ] > Task :app:mergeExtDexDebug UP-TO-DATE
[        ] > Task :app:mergeDexDebug UP-TO-DATE
[        ] > Task :app:mergeDebugJniLibFolders UP-TO-DATE
[        ] > Task :app:mergeDebugNativeLibs UP-TO-DATE
[        ] > Task :app:stripDebugDebugSymbols UP-TO-DATE
[        ] > Task :app:validateSigningDebug UP-TO-DATE
[        ] > Task :app:writeDebugAppMetadata UP-TO-DATE
[        ] > Task :app:writeDebugSigningConfigVersions UP-TO-DATE
[ +398 ms] > Task :app:compressDebugAssets
[        ] Execution optimizations have been disabled for task ':app:compressDebugAssets' to ensure correctness due to the following reasons:
[        ]   - Gradle detected a problem with the following location: '/home/sgehring/development/img_crash/build/app/intermediates/assets/debug/mergeDebugAssets'. Reason: Task ':app:compressDebugAssets' uses this output of task ':app:copyFlutterAssetsDebug' without declaring an explicit or implicit dependency. This can lead to incorrect results being produced, depending on what order the tasks are executed. Please refer to https://docs.gradle.org/7.4/userguide/validation_problems.html#implicit_dependency for more details about this problem.
[        ] > Task :app:packageDebug UP-TO-DATE
[        ] > Task :app:createDebugApkListingFileRedirect UP-TO-DATE
[ +226 ms] > Task :app:assembleDebug
[        ] Deprecated Gradle features were used in this build, making it incompatible with Gradle 8.0.
[        ] You can use '--warning-mode all' to show the individual deprecation warnings and determine if they come from your own scripts or plugins.
[        ] See https://docs.gradle.org/7.4/userguide/command_line_interface.html#sec:command_line_warnings
[        ] Execution optimizations have been disabled for 1 invalid unit(s) of work during this build to ensure correctness.
[        ] Please consult deprecation warnings for more details.
[        ] BUILD SUCCESSFUL in 1s
[        ] 35 actionable tasks: 5 executed, 30 up-to-date
[ +322 ms] Running Gradle task 'assembleDebug'... (completed in 2,220ms)
[ +241 ms] calculateSha: LocalDirectory: '/home/sgehring/development/img_crash/build/app/outputs/flutter-apk'/app.apk
[ +797 ms] ✓  Built build/app/outputs/flutter-apk/app-debug.apk.
[   +1 ms] executing: /home/sgehring/Android/Sdk/build-tools/32.0.0/aapt dump xmltree /home/sgehring/development/img_crash/build/app/outputs/flutter-apk/app.apk AndroidManifest.xml
[   +4 ms] Exit code 0 from: /home/sgehring/Android/Sdk/build-tools/32.0.0/aapt dump xmltree /home/sgehring/development/img_crash/build/app/outputs/flutter-apk/app.apk AndroidManifest.xml
[        ] N: android=http://schemas.android.com/apk/res/android
             E: manifest (line=2)
               A: android:versionCode(0x0101021b)=(type 0x10)0x1
               A: android:versionName(0x0101021c)="1.0.0" (Raw: "1.0.0")
               A: android:compileSdkVersion(0x01010572)=(type 0x10)0x1f
               A: android:compileSdkVersionCodename(0x01010573)="12" (Raw: "12")
               A: package="com.example.img_crash" (Raw: "com.example.img_crash")
               A: platformBuildVersionCode=(type 0x10)0x1f
               A: platformBuildVersionName=(type 0x10)0xc
               E: uses-sdk (line=7)
                 A: android:minSdkVersion(0x0101020c)=(type 0x10)0x10
                 A: android:targetSdkVersion(0x01010270)=(type 0x10)0x1f
               E: uses-permission (line=15)
                 A: android:name(0x01010003)="android.permission.INTERNET" (Raw: "android.permission.INTERNET")
               E: application (line=17)
                 A: android:label(0x01010001)="img_crash" (Raw: "img_crash")
                 A: android:icon(0x01010002)=@0x7f080000
                 A: android:name(0x01010003)="android.app.Application" (Raw: "android.app.Application")
                 A: android:debuggable(0x0101000f)=(type 0x12)0xffffffff
                 A: android:appComponentFactory(0x0101057a)="androidx.core.app.CoreComponentFactory" (Raw: "androidx.core.app.CoreComponentFactory")
                 E: activity (line=23)
                   A: android:theme(0x01010000)=@0x7f0a0000
                   A: android:name(0x01010003)="com.example.img_crash.MainActivity" (Raw: "com.example.img_crash.MainActivity")
                   A: android:exported(0x01010010)=(type 0x12)0xffffffff
                   A: android:launchMode(0x0101001d)=(type 0x10)0x1
                   A: android:configChanges(0x0101001f)=(type 0x11)0x40003fb4
                   A: android:windowSoftInputMode(0x0101022b)=(type 0x11)0x10
                   A: android:hardwareAccelerated(0x010102d3)=(type 0x12)0xffffffff
                   E: meta-data (line=38)
                     A: android:name(0x01010003)="io.flutter.embedding.android.NormalTheme" (Raw: "io.flutter.embedding.android.NormalTheme")
                     A: android:resource(0x01010025)=@0x7f0a0001
                   E: intent-filter (line=42)
                     E: action (line=43)
                       A: android:name(0x01010003)="android.intent.action.MAIN" (Raw: "android.intent.action.MAIN")
                     E: category (line=45)
                       A: android:name(0x01010003)="android.intent.category.LAUNCHER" (Raw: "android.intent.category.LAUNCHER")
                 E: meta-data (line=52)
                   A: android:name(0x01010003)="flutterEmbedding" (Raw: "flutterEmbedding")
                   A: android:value(0x01010024)=(type 0x10)0x2
                 E: uses-library (line=56)
                   A: android:name(0x01010003)="androidx.window.extensions" (Raw: "androidx.window.extensions")
                   A: android:required(0x0101028e)=(type 0x12)0x0
                 E: uses-library (line=59)
                   A: android:name(0x01010003)="androidx.window.sidecar" (Raw: "androidx.window.sidecar")
                   A: android:required(0x0101028e)=(type 0x12)0x0
[   +1 ms] Stopping app 'app.apk' on POCOPHONE F1.
[        ] executing: /home/sgehring/Android/Sdk/platform-tools/adb -s 802d5cf6 shell am force-stop com.example.img_crash
[ +141 ms] executing: /home/sgehring/Android/Sdk/platform-tools/adb -s 802d5cf6 shell pm list packages com.example.img_crash
[  +53 ms] package:com.example.img_crash
[   +1 ms] executing: /home/sgehring/Android/Sdk/platform-tools/adb -s 802d5cf6 shell cat /data/local/tmp/sky.com.example.img_crash.sha1
[  +23 ms] 16d353da7378d840781083f4c42d771bb650501a
[        ] Latest build already installed.
[        ] executing: /home/sgehring/Android/Sdk/platform-tools/adb -s 802d5cf6 shell -x logcat -v time -t 1
[  +58 ms] --------- beginning of main
           07-11 18:12:34.791 E/libc    (  886): Access denied finding property "ro.hardware.fp.sideCap"
[   +5 ms] executing: /home/sgehring/Android/Sdk/platform-tools/adb -s 802d5cf6 shell am start -a android.intent.action.RUN -f 0x20000000 --ez enable-dart-profiling true --ez enable-checked-mode true --ez verify-entry-points true com.example.img_crash/com.example.img_crash.MainActivity
[  +39 ms] Starting: Intent { act=android.intent.action.RUN flg=0x20000000 cmp=com.example.img_crash/.MainActivity (has extras) }
[        ] Waiting for observatory port to be available...
[ +304 ms] Observatory URL on device: http://127.0.0.1:37563/uysnDNSNtz0=/
[        ] executing: /home/sgehring/Android/Sdk/platform-tools/adb -s 802d5cf6 forward tcp:0 tcp:37563
[   +4 ms] 40351
[        ] Forwarded host port 40351 to device port 37563 for Observatory
[   +3 ms] Caching compiled dill
[  +93 ms] Connecting to service protocol: http://127.0.0.1:40351/uysnDNSNtz0=/
[ +188 ms] Launching a Dart Developer Service (DDS) instance at http://127.0.0.1:0, connecting to VM service at http://127.0.0.1:40351/uysnDNSNtz0=/.
[ +206 ms] DDS is listening at http://127.0.0.1:42901/urd1gqU3ucg=/.
[  +38 ms] Successfully connected to service protocol: http://127.0.0.1:40351/uysnDNSNtz0=/
[  +55 ms] DevFS: Creating new filesystem on the device (null)
[  +66 ms] DevFS: Created new filesystem on the device (file:///data/user/0/com.example.img_crash/code_cache/img_crashSIMNBV/img_crash/)
[   +1 ms] Updating assets
[  +45 ms] Syncing files to device POCOPHONE F1...
[        ] <- reset
[        ] Compiling dart to kernel with 0 updated files
[        ] Processing bundle.
[        ] <- recompile package:img_crash/main.dart 484060f0-4e1a-4bec-89d8-53221a5adbf7
[        ] <- 484060f0-4e1a-4bec-89d8-53221a5adbf7
[        ] Bundle processing done.
[  +45 ms] Updating files.
[        ] DevFS: Sync finished
[        ] Syncing files to device POCOPHONE F1... (completed in 48ms)
[        ] Synced 0.0MB.
[   +1 ms] <- accept
[   +2 ms] Connected to _flutterView/0x75873e5620.
[   +1 ms] Flutter run key commands.
[        ] r Hot reload. 🔥🔥🔥
[        ] R Hot restart.
[        ] h List all available interactive commands.
[        ] d Detach (terminate "flutter run" but leave application running).
[        ] c Clear the screen
[        ] q Quit (terminate the application on the device).
[        ] 💪 Running with sound null safety 💪
[        ] An Observatory debugger and profiler on POCOPHONE F1 is available at: http://127.0.0.1:42901/urd1gqU3ucg=/
[ +342 ms] D/skia    (28012): libjpeg error 68 <Unsupported marker type 0x73> from output_message
[        ] D/skia    (28012): libjpeg error 68 <Unsupported marker type 0x73> from ReadHeader
[        ] E/FlutterJNI(28012): Failed to decode image
[        ] E/FlutterJNI(28012): android.graphics.ImageDecoder$DecodeException: Failed to create image decoder with message 'invalid input'Input contained an error.
[        ] E/FlutterJNI(28012): 	at android.graphics.ImageDecoder.nCreate(Native Method)
[        ] E/FlutterJNI(28012): 	at android.graphics.ImageDecoder.access$200(ImageDecoder.java:173)
[        ] E/FlutterJNI(28012): 	at android.graphics.ImageDecoder$ByteBufferSource.createImageDecoder(ImageDecoder.java:250)
[        ] E/FlutterJNI(28012): 	at android.graphics.ImageDecoder.decodeBitmapImpl(ImageDecoder.java:1847)
[        ] E/FlutterJNI(28012): 	at android.graphics.ImageDecoder.decodeBitmap(ImageDecoder.java:1840)
[        ] E/FlutterJNI(28012): 	at io.flutter.embedding.engine.FlutterJNI.decodeImage(FlutterJNI.java:524)
[  +32 ms] I/flutter (28012): Error builder called!
[ +211 ms] W/Gralloc3(28012): mapper 3.x is not supported
[   +4 ms] The Flutter DevTools debugger and profiler on POCOPHONE F1 is available at: http://127.0.0.1:9102?uri=http://127.0.0.1:42901/urd1gqU3ucg=/
[+5336 ms] Application finished.
```

<!--
     Run `flutter analyze` and attach any output of that command below.
     If there are any analysis errors, try resolving them before filing this issue.
-->

```
Analyzing img_crash...                                                  

   info • The value of the field '_counter' isn't used • lib/main.dart:52:7 • unused_field
   info • Avoid `print` calls in production code • lib/main.dart:6947:11 • avoid_print

2 issues found. (ran in 1.6s)
```

<!-- Finally, paste the output of running `flutter doctor -v` here. -->

```
[✓] Flutter (Channel stable, 3.0.1, on Arch Linux 5.18.9-arch1-1, locale en_US.UTF-8)
    • Flutter version 3.0.1 at /home/sgehring/.asdf/installs/flutter/3.0.1-stable
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision fb57da5f94 (8 weeks ago), 2022-05-19 15:50:29 -0700
    • Engine revision caaafc5604
    • Dart version 2.17.1
    • DevTools version 2.12.2

[✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
    • Android SDK at /home/sgehring/Android/Sdk
    • Platform android-32, build-tools 32.0.0
    • Java binary at: /opt/android-studio/jre/bin/java
    • Java version OpenJDK Runtime Environment (build 11.0.12+0-b1504.28-7817840)
    • All Android licenses accepted.

[✓] Chrome - develop for the web
    • CHROME_EXECUTABLE = /usr/bin/chrome

[✓] Linux toolchain - develop for Linux desktop
    • clang version 14.0.6
    • cmake version 3.23.2
    • ninja version 1.11.0
    • pkg-config version 1.8.0

[✓] Android Studio (version 2021.1)
    • Android Studio at /opt/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 11.0.12+0-b1504.28-7817840)

[✓] Connected device (3 available)
    • POCOPHONE F1 (mobile) • 802d5cf6 • android-arm64  • Android 10 (API 29)
    • Linux (desktop)       • linux    • linux-x64      • Arch Linux 5.18.9-arch1-1
    • Chrome (web)          • chrome   • web-javascript • Chromium 103.0.5060.114 Arch Linux

[✓] HTTP Host Availability
    • All required HTTP hosts are available

• No issues found!

```

</details>


<!--
      Consider also attaching screenshots and/or videos to better
      illustrate the issue.

      You can upload them directly on GitHub.
      Beware that video file size is limited to 10MB.
-->

**Why is this an issue?** We use `Image` for displaying (M)JPEG streams fetched from cameras. Due to network issues or encoding errors in cheap devices, the app sometimes receives invalid JPEG frames that we would like to discard safely. 

Thank you for maintaining Flutter. I searched for this in the open issues but could not find anything that looks like the same issue.