Skip to content

[Web Canvaskit] ImageCodecException for certain JPEG files #100055

@edhom

Description

@edhom

Description

Certain JPEG images cannot be processed by flutter web on beta. An ImageCodecException is thrown, stating that the file format could not be detected based on the header. The header however is fine afaic [0xff 0xd8 0xff 0xe2 0x0c 0x58 0x49 0x43 0x43 0x5f]. The problem occurs for us primarily with images downloaded from Google Drive. Comparing the original files and the ones processed by Drive, the progressive Huffman encoding could cause the issue.

Stable Beta
Mobile
Web

Steps to Reproduce

You can use the following files and the given code sample to reproduce the issue:

Original Google Drive processed
non_drive drive
Expected results Actual result
expected actual
Code sample
import 'package:flutter/material.dart';

void main() {
  runApp(const Example());
}

class Example extends StatelessWidget {
  const Example({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Column(
      children: [
        Image.asset('assets/non_drive.jpg'),
        Image.asset('assets/drive.jpg'),
      ],
    );
  }
}
Logs
======== Exception caught by image resource service ================================================
The following ImageCodecException was thrown resolving an image codec:
Failed to detect image file format using the file header.
File header was [0xff 0xd8 0xff 0xe2 0x0c 0x58 0x49 0x43 0x43 0x5f].
Image source: encoded image bytes

When the exception was thrown, this was the stack: 
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 251:49  throw_
lib/_engine/engine/canvaskit/image_web_codecs.dart 52:7                       create
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54            runBody
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 123:5            _async
lib/_engine/engine/canvaskit/image_web_codecs.dart 35:46                      create
lib/_engine/engine/canvaskit/image.dart 15:34                                 skiaInstantiateImageCodec
lib/ui/painting.dart 466:19                                                   instantiateImageCodec
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 84:54            runBody
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 123:5            _async
lib/ui/painting.dart 459:36                                                   instantiateImageCodec
packages/flutter/src/painting/binding.dart 106:15                             instantiateImageCodec
packages/flutter/src/painting/image_provider.dart 684:18                      _loadAsync
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 45:50            <fn>
dart-sdk/lib/async/zone.dart 1434:47                                          _rootRunUnary
dart-sdk/lib/async/zone.dart 1335:19                                          runUnary
dart-sdk/lib/async/future_impl.dart 156:18                                    handleValue
dart-sdk/lib/async/future_impl.dart 740:44                                    handleValueCallback
dart-sdk/lib/async/future_impl.dart 769:13                                    _propagateToListeners
dart-sdk/lib/async/future_impl.dart 575:5                                     [_completeWithValue]
dart-sdk/lib/async/future_impl.dart 613:7                                     <fn>
dart-sdk/lib/async/zone.dart 1426:13                                          _rootRun
dart-sdk/lib/async/zone.dart 1328:19                                          run
dart-sdk/lib/async/zone.dart 1236:7                                           runGuarded
dart-sdk/lib/async/zone.dart 1276:23                                          callback
dart-sdk/lib/async/schedule_microtask.dart 40:11                              _microtaskLoop
dart-sdk/lib/async/schedule_microtask.dart 49:5                               _startMicrotaskLoop
dart-sdk/lib/_internal/js_dev_runtime/patch/async_patch.dart 166:15           <fn>
Image provider: AssetImage(bundle: null, name: "assets/drive.jpg")
Image key: AssetBundleImageKey(bundle: PlatformAssetBundle#27d86(), name: "assets/drive.jpg", scale: 1)
Analyzing bug...                                                        
No issues found! (ran in 2.1s)
[✓] Flutter (Channel beta, 2.11.0-0.1.pre, on macOS 11.4 20F71 darwin-x64, locale en-US)
    • Flutter version 2.11.0-0.1.pre at /Library/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision b101bfe32f (4 weeks ago), 2022-02-16 07:36:54 -0800
    • Engine revision e355993572
    • Dart version 2.17.0 (build 2.17.0-69.2.beta)
    • DevTools version 2.10.0-dev.1

Metadata

Metadata

Labels

P0Critical issues such as a build break or regressiona: imagesLoading, displaying, rendering imagesc: regressionIt was better in the past than it is nowe: web_canvaskitCanvasKit (a.k.a. Skia-on-WebGL) rendering backend for Webfound in release: 2.11Found to occur in 2.11frameworkflutter/packages/flutter repository. See also f: labels.platform-webWeb applications specificallyr: fixedIssue is closed as already fixed in a newer version

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions