Repository: flutter
Issue: [Web][Canvaskit] Image decode crash on non-Blink browsers
Labels: c: crash,engine,platform-web,a: images,e: web_canvaskit,has reproducible steps,P2,found in release: 3.3,found in release: 3.6,team-web,triaged-web

<!-- 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. Clone the repo and run the web server
```
git clone https://github.com/umberto-sonnino/flutter_web_decode_bug.git
cd flutter_web_decode_bug
flutter run -d web-server --web-renderer canvaskit
```
2. Open the app in a non-Blink browser (i.e. Firefox or Safari) and open up the Developer Console
3. Click on 'Get Codecs' and wait for the console crash after a few images have been decoded

**Expected results:** <!-- what did you want to see? -->
Decoding the images doesn't crash

**Actual results:** <!-- what did you see? -->
I've seen different crashes depending on the browser. 
Firefox Developer Edition v108.0b5:
`Uncaught (in promise) Error: ImageCodecException: Failed to decode image data.
Image source: encoded image bytes`

StackTrace:
<details>

```
DartError dart_sdk.js:7028
    throw_ errors.dart:266
    createDefault image_wasm_codecs.dart:36
    new skia_object_cache.dart:222
    decodeFromBytes image_wasm_codecs.dart:21
    skiaInstantiateImageCodec image.dart:22
    instantiateImageCodec painting.dart:480
    runBody async_patch.dart:84
    _async async_patch.dart:123
    instantiateImageCodec painting.dart:473
    _initCodecs main.dart:47
    runUnary zone.dart:1653
    handleValue future_impl.dart:147
    handleValueCallback future_impl.dart:766
    _propagateToListeners future_impl.dart:795
    _completeWithValue future_impl.dart:566
    <anonymous> future_impl.dart:639
    _microtaskLoop schedule_microtask.dart:40
    _startMicrotaskLoop schedule_microtask.dart:49
    _scheduleImmediateWithPromise async_patch.dart:166
    promise callback*_scheduleImmediateWithPromise async_patch.dart:164
    _scheduleImmediate async_patch.dart:136
    _scheduleAsyncCallback schedule_microtask.dart:69
    _rootScheduleMicrotask zone.dart:1458
    scheduleMicrotask zone.dart:1673
    _asyncCompleteWithValue future_impl.dart:638
    _asyncComplete future_impl.dart:598
    complete future_impl.dart:36
    send binding.dart:366
    runUnaryGuarded zone.dart:1586
    _zonedPlatformMessageResponseCallback platform_dispatcher.dart:381
    replyToPlatformMessage platform_dispatcher.dart:1138
    runUnary zone.dart:1653
    handleValue future_impl.dart:147
    handleValueCallback future_impl.dart:766
    _propagateToListeners future_impl.dart:795
    _complete future_impl.dart:557
    delayed future.dart:421
    internalCallback isolate_helper.dart:48
    setTimeout handler*load__dart_sdk/_isolate_helper.TimerImpl.new isolate_helper.dart:55
    _createTimer async_patch.dart:186
    createTimer zone.dart:1677
    new timer.dart:51
    delayed future.dart:419
    replyToPlatformMessage platform_dispatcher.dart:1136
    <anonymous> platform_dispatcher.dart:437
    runUnary zone.dart:1653
    handleValue future_impl.dart:147
    handleValueCallback future_impl.dart:766
    _propagateToListeners future_impl.dart:795
    _completeWithValue future_impl.dart:566
    <anonymous> future_impl.dart:639
    _microtaskLoop schedule_microtask.dart:40
    _startMicrotaskLoop schedule_microtask.dart:49
    _scheduleImmediateWithPromise async_patch.dart:166
    promise callback*_scheduleImmediateWithPromise async_patch.dart:164
    _scheduleImmediate async_patch.dart:136
    _scheduleAsyncCallback schedule_microtask.dart:69
    _rootScheduleMicrotask zone.dart:1458
    scheduleMicrotask zone.dart:1673
    _asyncCompleteWithValue future_impl.dart:638
    _asyncComplete future_impl.dart:598
    complete future_impl.dart:36
    domHttpRequest dom.dart:733
    _checkAndCall operations.dart:334
    dcall operations.dart:339
    ret dart_sdk.js:62137
    callMethod$ js_util_patch.dart:80
    DomEventTargetExtension$124addEventListener dom.dart:136
    domHttpRequest dom.dart:726
    load assets.dart:61
    runBody async_patch.dart:84
    _async async_patch.dart:123
    load assets.dart:57
    _sendPlatformMessage platform_dispatcher.dart:436
    sendPlatformMessage platform_dispatcher.dart:326
    send binding.dart:364
    load asset_bundle.dart:256
    runBody async_patch.dart:84
    _async async_patch.dart:123
    load asset_bundle.dart:253
    _initCodecs main.dart:48
    moveNext iterable.dart:391
    next dart_sdk.js:7061
    wait future.dart:520
    _initCodecs main.dart:43
    _async async_patch.dart:45
    runUnary zone.dart:1653
    handleValue future_impl.dart:147
    handleValueCallback future_impl.dart:766
    _propagateToListeners future_impl.dart:795
    _completeWithValue future_impl.dart:566
    <anonymous> future_impl.dart:639
[dart_sdk.js:7028:7](http://localhost:57101/dart_sdk.js)
    _startMicrotaskLoop schedule_microtask.dart:54
    _scheduleImmediateWithPromise async_patch.dart:166
    (Async: promise callback)
    _scheduleImmediateWithPromise async_patch.dart:164
    _scheduleImmediate async_patch.dart:136
    _scheduleAsyncCallback schedule_microtask.dart:69
    _rootScheduleMicrotask zone.dart:1458
    scheduleMicrotask zone.dart:1673
    _asyncCompleteWithValue future_impl.dart:638
    _asyncComplete future_impl.dart:598
    complete future_impl.dart:36
    send binding.dart:366
    runUnaryGuarded zone.dart:1586
    _zonedPlatformMessageResponseCallback platform_dispatcher.dart:381
    replyToPlatformMessage platform_dispatcher.dart:1138
    runUnary zone.dart:1653
    handleValue future_impl.dart:147
    handleValueCallback future_impl.dart:766
    _propagateToListeners future_impl.dart:795
    _complete future_impl.dart:557
    delayed future.dart:421
    internalCallback isolate_helper.dart:48
    (Async: setTimeout handler)
    new isolate_helper.dart:55
    _createTimer async_patch.dart:186
    createTimer zone.dart:1677
    new timer.dart:51
    delayed future.dart:419
    replyToPlatformMessage platform_dispatcher.dart:1136
    <anonymous> platform_dispatcher.dart:437
    runUnary zone.dart:1653
    handleValue future_impl.dart:147
    handleValueCallback future_impl.dart:766
    _propagateToListeners future_impl.dart:795
    _completeWithValue future_impl.dart:566
    <anonymous> future_impl.dart:639
    _microtaskLoop schedule_microtask.dart:40
    _startMicrotaskLoop schedule_microtask.dart:49
    _scheduleImmediateWithPromise async_patch.dart:166
    (Async: promise callback)
    _scheduleImmediateWithPromise async_patch.dart:164
    _scheduleImmediate async_patch.dart:136
    _scheduleAsyncCallback schedule_microtask.dart:69
    _rootScheduleMicrotask zone.dart:1458
    scheduleMicrotask zone.dart:1673
    _asyncCompleteWithValue future_impl.dart:638
    _asyncComplete future_impl.dart:598
    complete future_impl.dart:36
    domHttpRequest dom.dart:733
    _checkAndCall operations.dart:334
    dcall operations.dart:339
    ret dart_sdk.js:62137
    (Async: EventListener.handleEvent)
    callMethod$ js_util_patch.dart:80
    DomEventTargetExtension$124addEventListener dom.dart:136
    domHttpRequest dom.dart:726
    load assets.dart:61
    next self-hosted:1740
    runBody async_patch.dart:84
    _async async_patch.dart:123
    load assets.dart:57
    _sendPlatformMessage platform_dispatcher.dart:436
    sendPlatformMessage platform_dispatcher.dart:326
    send binding.dart:364
    load asset_bundle.dart:256
    next self-hosted:1740
    runBody async_patch.dart:84
    _async async_patch.dart:123
    load asset_bundle.dart:253
    _initCodecs main.dart:48
    moveNext iterable.dart:391
    next dart_sdk.js:7061
    wait future.dart:520
    _initCodecs main.dart:43
    InterpretGeneratorResume self-hosted:1819
    next self-hosted:1740
    _async async_patch.dart:45
    runUnary zone.dart:1653
    handleValue future_impl.dart:147
    handleValueCallback future_impl.dart:766
    _propagateToListeners future_impl.dart:795
    _completeWithValue future_impl.dart:566
    <anonymous> future_impl.dart:639
```

</details>

Safari v16.1:
`Unhandled Promise Rejection Error`

StackTrace:
<details>

```
throw _ -- errors.dart:266
  collectSkiaObjectsNow -- canvaskit_api.dart:2376
  (anonymous function) -- canvaskit_api:2324
  internalCallback -- isolate helper:48
```

</details>

This is running on macOS 13.0.1
Flutter version 3.3.7
Dart 2.18.4