Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/ImageSharp/Formats/Gif/GifDecoderCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,11 @@ private void ReadComments(BufferedReadStream stream)
GifThrowHelper.ThrowInvalidImageContentException($"Gif comment length '{length}' exceeds max '{GifConstants.MaxCommentSubBlockLength}' of a comment data block");
}

if (length == -1)
Copy link

Copilot AI Jun 24, 2025

Choose a reason for hiding this comment

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

[nitpick] Consider moving the EOF check (length < 0) before the max-length validation to follow a consistent ordering of bounds checks and avoid any accidental fall-through.

Copilot uses AI. Check for mistakes.

{
GifThrowHelper.ThrowInvalidImageContentException("Unexpected end of stream while reading gif comment");
Copy link

Copilot AI Jun 24, 2025

Choose a reason for hiding this comment

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

[nitpick] The exception message uses lowercase 'gif'; for consistency with other GIF-related messages in the codebase, consider capitalizing it to 'GIF'.

Suggested change
GifThrowHelper.ThrowInvalidImageContentException("Unexpected end of stream while reading gif comment");
GifThrowHelper.ThrowInvalidImageContentException("Unexpected end of stream while reading GIF comment");

Copilot uses AI. Check for mistakes.

}

if (this.skipMetadata)
{
stream.Seek(length, SeekOrigin.Current);
Expand Down
17 changes: 17 additions & 0 deletions tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -381,4 +381,21 @@ public void Issue2859_LZWPixelStackOverflow<TPixel>(TestImageProvider<TPixel> pr
image.DebugSaveMultiFrame(provider);
image.CompareToReferenceOutputMultiFrame(provider, ImageComparer.Exact);
}

// https://github.com/SixLabors/ImageSharp/issues/2953
[Theory]
[WithFile(TestImages.Gif.Issues.Issue2953, PixelTypes.Rgba32)]
public void Issue2953<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
// We should throw a InvalidImageContentException when trying to identify or load an invalid GIF file.
Copy link

Copilot AI Jun 24, 2025

Choose a reason for hiding this comment

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

Replace 'a InvalidImageContentException' with 'an InvalidImageContentException' to correct the article usage.

Suggested change
// We should throw a InvalidImageContentException when trying to identify or load an invalid GIF file.
// We should throw an InvalidImageContentException when trying to identify or load an invalid GIF file.

Copilot uses AI. Check for mistakes.

TestFile testFile = TestFile.Create(provider.SourceFileOrDescription);

Assert.Throws<InvalidImageContentException>(() => Image.Identify(testFile.FullPath));
Assert.Throws<InvalidImageContentException>(() => Image.Load(testFile.FullPath));

DecoderOptions options = new() { SkipMetadata = true };
Assert.Throws<InvalidImageContentException>(() => Image.Identify(options, testFile.FullPath));
Assert.Throws<InvalidImageContentException>(() => Image.Load(options, testFile.FullPath));
}
}
1 change: 1 addition & 0 deletions tests/ImageSharp.Tests/TestImages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,7 @@ public static class Issues
public const string Issue2866 = "Gif/issues/issue_2866.gif";
public const string Issue2859_A = "Gif/issues/issue_2859_A.gif";
public const string Issue2859_B = "Gif/issues/issue_2859_B.gif";
public const string Issue2953 = "Gif/issues/issue_2953.gif";
}

public static readonly string[] Animated =
Expand Down
3 changes: 3 additions & 0 deletions tests/Images/Input/Gif/issues/issue_2953.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading