-
-
Notifications
You must be signed in to change notification settings - Fork 888
GIF: Check for end of stream when reading comments. #2954
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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) | ||||||
{ | ||||||
GifThrowHelper.ThrowInvalidImageContentException("Unexpected end of stream while reading gif comment"); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
} | ||||||
|
||||||
if (this.skipMetadata) | ||||||
{ | ||||||
stream.Seek(length, SeekOrigin.Current); | ||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -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. | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Copilot uses AI. Check for mistakes. Positive FeedbackNegative Feedback |
||||||
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)); | ||||||
} | ||||||
} |
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.
[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.