Support GIF files without 0x3B trailer byte#55
Conversation
Co-authored-by: CaiJingLong <14145407+CaiJingLong@users.noreply.github.com>
Co-authored-by: CaiJingLong <14145407+CaiJingLong@users.noreply.github.com>
Co-authored-by: CaiJingLong <14145407+CaiJingLong@users.noreply.github.com>
Co-authored-by: CaiJingLong <14145407+CaiJingLong@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR enhances the GIF decoder to accept non-standard GIF files that omit the 0x3B trailer byte, which some GIF encoders produce. Since GIF dimensions are extracted from header bytes 6-10 (not the trailer), relaxing footer validation is safe for this library's purpose.
Key Changes
- Modified GIF decoder validation to accept both standard GIFs (with 0x3B trailer) and non-standard GIFs (without trailer) using an empty footer option
- Added comprehensive test coverage for non-standard GIF format validation
- Updated dependencies from regional mirror (pub.flutter-io.cn) to official Dart package repository (pub.dev)
Reviewed changes
Copilot reviewed 2 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
packages/image_size_getter/lib/src/decoder/impl/gif_decoder.dart |
Added empty footer option (emptyEnd) to mutipleEndBytesList to accept GIFs without 0x3B trailer; includes detailed documentation explaining the rationale |
packages/image_size_getter/test/non_standard_gif_test.dart |
New comprehensive test suite covering non-standard GIF validation, standard GIF comparison tests, and verification that invalid headers are still rejected |
pubspec.lock |
Routine dependency updates and migration from regional mirror to official pub.dev repository |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| test('Test GIF89a format with and without trailer', () { | ||
| final gif89a = File('../../example/asset/dialog.gif'); | ||
|
|
||
| const GifDecoder decoder = GifDecoder(); | ||
| final input = FileInput(gif89a); | ||
|
|
||
| // Standard GIF89a should still work | ||
| expect(decoder.isValid(input), isTrue); | ||
| expect(decoder.getSize(input), Size(688, 1326)); | ||
| }); |
There was a problem hiding this comment.
The test name and comment suggest testing "with and without trailer" but this test only validates a single standard GIF file (dialog.gif) that presumably has the 0x3B trailer. To match the test description, consider either renaming this test to clarify it's only testing the standard format, or adding a corresponding test case for a GIF89a file without a trailer (similar to non_standard_ending.gif).
Some GIF encoders produce valid files that omit the standard 0x3B trailer byte. The decoder was rejecting these files despite containing valid size information in the header.
Changes
mutipleEndBytesListnon_standard_ending.gif(GIF87a without trailer)Rationale
GIF dimensions are read from header bytes 6-10, not the trailer. The library's purpose is size extraction, not comprehensive format validation. Header validation remains intact.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
github-production-user-asset-6210df.s3.amazonaws.com/usr/bin/curl curl -L -o non_standard_ending.gif REDACTED(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.