mirror of
https://github.com/mozilla-firefox/firefox
synced 2026-08-12 12:35:33 +00:00
Some animated GIFs have a first-frame delay of zero (or no Graphic Control Extension for the first frame). The metadata decoder terminates after parsing the first frame's image descriptor without ever encountering a second frame, so it reports the image as non-animated. Previously, `AnonymousDecoderImpl` would trust this result, set `frameCount=1`/`frameCountComplete=true`, and destroy the frame count task. This caused `ImageDecoder` to return zero for frame count making code running it consider the GIF to be non-animated, differing from the rendering result when such a GIF presents in DOM. The fix always runs the frame count task after metadata completes, even when the metadata decoder reported non-animated. The frame count task does a full parse (with `COUNT_FRAMES` flag) and will discover additional frames. If it finds more than one frame, we update the animated flag before resolving the metadata promise to `ImageDecoder`. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Differential Revision: https://phabricator.services.mozilla.com/D298735
49 lines
2.1 KiB
JavaScript
49 lines
2.1 KiB
JavaScript
// META: global=window,dedicatedworker
|
|
|
|
// Bug: An animated GIF whose first frame has delay_time=0 is incorrectly
|
|
// detected as non-animated by the metadata decoder. This causes ImageDecoder
|
|
// to report frameCount=1 and reject decode requests for subsequent frames.
|
|
|
|
promise_test(async t => {
|
|
let support = await ImageDecoder.isTypeSupported('image/gif');
|
|
assert_implements_optional(support, 'Optional codec image/gif not supported.');
|
|
|
|
let response = await fetch('animated-zero-delay.gif');
|
|
let buffer = await response.arrayBuffer();
|
|
let decoder = new ImageDecoder({data: buffer, type: 'image/gif'});
|
|
|
|
await decoder.tracks.ready;
|
|
assert_equals(decoder.tracks.length, 1, 'Should have one track');
|
|
|
|
let track = decoder.tracks.selectedTrack;
|
|
assert_true(track.animated, 'Track should be detected as animated');
|
|
assert_equals(track.frameCount, 2, 'Should report 2 frames');
|
|
|
|
let result0 = await decoder.decode({frameIndex: 0});
|
|
assert_true(result0.complete, 'Frame 0 should be complete');
|
|
assert_equals(result0.image.codedWidth, 2);
|
|
assert_equals(result0.image.codedHeight, 2);
|
|
|
|
let result1 = await decoder.decode({frameIndex: 1});
|
|
assert_true(result1.complete, 'Frame 1 should be complete');
|
|
assert_equals(result1.image.codedWidth, 2);
|
|
assert_equals(result1.image.codedHeight, 2);
|
|
}, 'Test animated GIF with zero first-frame delay decodes all frames');
|
|
|
|
promise_test(async t => {
|
|
let support = await ImageDecoder.isTypeSupported('image/gif');
|
|
assert_implements_optional(support, 'Optional codec image/gif not supported.');
|
|
|
|
let response = await fetch('animated-zero-delay.gif');
|
|
let buffer = await response.arrayBuffer();
|
|
let decoder = new ImageDecoder({data: buffer, type: 'image/gif'});
|
|
|
|
await decoder.completed;
|
|
|
|
let track = decoder.tracks.selectedTrack;
|
|
assert_true(track.animated, 'Track should be animated after completed');
|
|
assert_equals(track.frameCount, 2, 'Should report 2 frames after completed');
|
|
assert_equals(track.repetitionCount, Infinity,
|
|
'Should report infinite repetitions (loop=0)');
|
|
}, 'Test animated GIF with zero first-frame delay reports correct metadata');
|