Skip to content
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

Fix GIF parser #7

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Fix GIF parser #7

wants to merge 2 commits into from

Conversation

ojii
Copy link
Owner

@ojii ojii commented Aug 22, 2024

Previously, the GIF parser would assume a GIF is animated if it had the Netscape Application Extension. This can lead to false positives where a GIF can have all the indicators of an animated GIF but only one Image Descriptor.

Now, the code checks for the absence of the Graphic Control Extension before an Image Descriptor to mean non-animated and otherwise checks if there are multiple Image Descriptors. This unfortunately requires parsing much further into the data stream.

The example cli now also supports specifiying the buffer size.

Fixes #7

Previously, the GIF parser would assume a GIF is animated if it had the
Netscape Application Extension. This can lead to false positives where a
GIF can have all the indicators of an animated GIF but only one Image
Descriptor.

Now, the code checks for the absence of the Graphic Control Extension
before an Image Descriptor to mean non-animated and otherwise checks if
there are multiple Image Descriptors. This unfortunately requires
parsing much further into the data stream.

The example cli now also supports specifiying the buffer size.
Comment on lines +39 to +40
if let Some(size) = color_table_size(flags) {
cursor.seek(SeekFrom::Current(size))?;
Copy link
Contributor

Choose a reason for hiding this comment

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

:nit:

Suggested change
if let Some(size) = color_table_size(flags) {
cursor.seek(SeekFrom::Current(size))?;
if let Some(size) = color_table_size(flags) {
// skip Local Color Table
cursor.seek(SeekFrom::Current(size))?;

Copy link
Contributor

@FurqanHabibi FurqanHabibi left a comment

Choose a reason for hiding this comment

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

Usually, the "NETSCAPE2.0" Application Extension is used for looping
GIFs and the Graphic Control Extension is used for animated GIFs.
However, such files can still have only a single image, resulting in a
non-animated GIF. While rather nonsensical, these files should still be
handled correctly, so one such file was crafted for testing.
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.

2 participants