Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit fb0fd74

Browse files
author
Harry Terkelsen
authored
Update the magic number for JPEG to just FF D8 FF. (#32076)
1 parent eb1c50d commit fb0fd74

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

lib/web_ui/lib/src/engine/canvaskit/image_web_codecs.dart

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,7 @@ class ImageFileFormat {
297297
ImageFileFormat(<int?>[0x47, 0x49, 0x46, 0x38, 0x39, 0x61], 'image/gif'),
298298

299299
// JPEG
300-
ImageFileFormat(<int?>[0xFF, 0xD8, 0xFF, 0xDB], 'image/jpeg'),
301-
ImageFileFormat(<int?>[0xFF, 0xD8, 0xFF, 0xE0, 0x00, 0x10, 0x4A, 0x46, 0x49, 0x46, 0x00, 0x01], 'image/jpeg'),
302-
ImageFileFormat(<int?>[0xFF, 0xD8, 0xFF, 0xEE], 'image/jpeg'),
303-
ImageFileFormat(<int?>[0xFF, 0xD8, 0xFF, 0xE1], 'image/jpeg'),
300+
ImageFileFormat(<int?>[0xFF, 0xD8, 0xFF], 'image/jpeg'),
304301

305302
// WebP
306303
ImageFileFormat(<int?>[0x52, 0x49, 0x46, 0x46, null, null, null, null, 0x57, 0x45, 0x42, 0x50], 'image/webp'),

lib/web_ui/test/canvaskit/image_golden_test.dart

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -529,6 +529,13 @@ void _testForImageCodecs({required bool useBrowserImageDecoder}) {
529529

530530
await disposePlatformView(0);
531531
});
532+
533+
test('can detect JPEG from just magic number', () async {
534+
expect(
535+
detectContentType(
536+
Uint8List.fromList(<int>[0xff, 0xd8, 0xff, 0xe2, 0x0c, 0x58, 0x49, 0x43, 0x43, 0x5f])),
537+
'image/jpeg');
538+
});
532539
});
533540
}
534541

0 commit comments

Comments
 (0)