Skip to content

Support GIF files without 0x3B trailer byte#55

Merged
CaiJingLong merged 5 commits intomainfrom
copilot/fix-gif-format-issue
Dec 13, 2025
Merged

Support GIF files without 0x3B trailer byte#55
CaiJingLong merged 5 commits intomainfrom
copilot/fix-gif-format-issue

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Dec 13, 2025

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

  • GIF decoder validation: Accept both standard GIFs (with 0x3B trailer) and non-standard GIFs (without trailer) by adding an empty footer option to mutipleEndBytesList
  • Test coverage: Added test cases for non-standard GIF format and verification that invalid headers are still rejected
  • Test asset: Added non_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.

// Before: Rejected GIFs without 0x3B
List<List<int>> get mutipleEndBytesList => [end];

// After: Accept both with and without trailer
List<List<int>> get mutipleEndBytesList => [end, emptyEnd];

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
    • Triggering command: /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

This section details on the original issue you should resolve

<issue_title>[Bug report] Some GIF formats are not standard</issue_title>
<issue_description>### Version

2.4.1

Platforms

dart

Device Model

flutter info

*

How to reproduce?

Image
Some gifs do not end with 0x3B

Logs

Example code (optional)

Contact

No response</issue_description>

<agent_instructions>帮我尝试复现并修复这个问题</agent_instructions>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 4 commits December 13, 2025 12:00
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>
Copilot AI changed the title [WIP] Fix GIF format handling for non-standard endings Support GIF files without 0x3B trailer byte Dec 13, 2025
Copilot AI requested a review from CaiJingLong December 13, 2025 12:08
@CaiJingLong CaiJingLong marked this pull request as ready for review December 13, 2025 12:17
Copilot AI review requested due to automatic review settings December 13, 2025 12:17
@CaiJingLong CaiJingLong merged commit 3ccea4b into main Dec 13, 2025
8 checks passed
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +33 to +42
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));
});
Copy link

Copilot AI Dec 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug report] Some GIF formats are not standard

3 participants