-
Notifications
You must be signed in to change notification settings - Fork 37
Support GIF files without 0x3B trailer byte #55
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
6f26402
Initial plan
Copilot e38d8d2
Add test file for non-standard GIF format issue
Copilot 27051b1
Fix GIF decoder to accept non-standard GIFs without 0x3B trailer
Copilot 55755f2
Add comprehensive tests and documentation for non-standard GIF support
Copilot 8c8a663
Improve test cleanup using temporary directory
Copilot File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
66 changes: 66 additions & 0 deletions
66
packages/image_size_getter/test/non_standard_gif_test.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| import 'dart:io'; | ||
|
|
||
| import 'package:image_size_getter/file_input.dart'; | ||
| import 'package:image_size_getter/image_size_getter.dart'; | ||
| import 'package:test/test.dart'; | ||
|
|
||
| void main() { | ||
| group('Test non-standard GIF (without 0x3B ending)', () { | ||
| test('Test GIF without 0x3B trailer', () { | ||
| final gif = File('../../example/asset/non_standard_ending.gif'); | ||
|
|
||
| const GifDecoder decoder = GifDecoder(); | ||
| final input = FileInput(gif); | ||
|
|
||
| // The file should still be valid even without 0x3B ending | ||
| expect(decoder.isValid(input), isTrue, | ||
| reason: 'GIF should be valid even without 0x3B trailer'); | ||
|
|
||
| // Size should still be readable | ||
| expect(decoder.getSize(input), Size(200, 150)); | ||
| }); | ||
|
|
||
| test('Test standard GIF with 0x3B trailer for comparison', () { | ||
| final gif = File('../../example/asset/87a.gif'); | ||
|
|
||
| const GifDecoder decoder = GifDecoder(); | ||
| final input = FileInput(gif); | ||
|
|
||
| expect(decoder.isValid(input), isTrue); | ||
| expect(decoder.getSize(input), Size(200, 150)); | ||
| }); | ||
|
|
||
| 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)); | ||
| }); | ||
|
|
||
| test('Test that invalid headers are still rejected', () { | ||
| // Create a file with invalid header in a temporary directory | ||
| final tempDir = Directory.systemTemp.createTempSync('gif_test_'); | ||
| final tempFile = File('${tempDir.path}/temp_invalid.gif'); | ||
|
|
||
| try { | ||
| tempFile.writeAsBytesSync([0x47, 0x49, 0x46, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]); | ||
|
|
||
| const GifDecoder decoder = GifDecoder(); | ||
| final input = FileInput(tempFile); | ||
|
|
||
| // Invalid GIF header should be rejected | ||
| expect(decoder.isValid(input), isFalse, | ||
| reason: 'File with invalid GIF header should be rejected'); | ||
| } finally { | ||
| // Clean up temp directory and all its contents | ||
| if (tempDir.existsSync()) { | ||
| tempDir.deleteSync(recursive: true); | ||
| } | ||
| } | ||
| }); | ||
| }); | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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).