Skip to content

Commit 55e4926

Browse files
Fix #2953
1 parent d133ef9 commit 55e4926

File tree

5 files changed

+32
-11
lines changed

5 files changed

+32
-11
lines changed

.gitattributes

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,6 @@
115115
*.jpg filter=lfs diff=lfs merge=lfs -text
116116
*.jpeg filter=lfs diff=lfs merge=lfs -text
117117
*.bmp filter=lfs diff=lfs merge=lfs -text
118-
*.BMP filter=lfs diff=lfs merge=lfs -text
119118
*.gif filter=lfs diff=lfs merge=lfs -text
120119
*.png filter=lfs diff=lfs merge=lfs -text
121120
*.tif filter=lfs diff=lfs merge=lfs -text

src/ImageSharp/Formats/Gif/GifDecoderCore.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,11 @@ private void ReadComments(BufferedReadStream stream)
402402
GifThrowHelper.ThrowInvalidImageContentException($"Gif comment length '{length}' exceeds max '{GifConstants.MaxCommentSubBlockLength}' of a comment data block");
403403
}
404404

405+
if (length == -1)
406+
{
407+
GifThrowHelper.ThrowInvalidImageContentException("Unexpected end of stream while reading gif comment");
408+
}
409+
405410
if (this.skipMetadata)
406411
{
407412
stream.Seek(length, SeekOrigin.Current);

tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -183,16 +183,16 @@ public void Issue1530_BadDescriptorDimensions<TPixel>(TestImageProvider<TPixel>
183183
image.CompareToReferenceOutputMultiFrame(provider, ImageComparer.Exact);
184184
}
185185

186-
// https://github.com/SixLabors/ImageSharp/issues/2758
187-
[Theory]
188-
[WithFile(TestImages.Gif.Issues.Issue2758, PixelTypes.Rgba32)]
189-
public void Issue2758_BadDescriptorDimensions<TPixel>(TestImageProvider<TPixel> provider)
190-
where TPixel : unmanaged, IPixel<TPixel>
191-
{
192-
using Image<TPixel> image = provider.GetImage();
193-
image.DebugSaveMultiFrame(provider);
194-
image.CompareToReferenceOutputMultiFrame(provider, ImageComparer.Exact);
195-
}
186+
// https://github.com/SixLabors/ImageSharp/issues/2758
187+
[Theory]
188+
[WithFile(TestImages.Gif.Issues.Issue2758, PixelTypes.Rgba32)]
189+
public void Issue2758_BadDescriptorDimensions<TPixel>(TestImageProvider<TPixel> provider)
190+
where TPixel : unmanaged, IPixel<TPixel>
191+
{
192+
using Image<TPixel> image = provider.GetImage();
193+
image.DebugSaveMultiFrame(provider);
194+
image.CompareToReferenceOutputMultiFrame(provider, ImageComparer.Exact);
195+
}
196196

197197
// https://github.com/SixLabors/ImageSharp/issues/405
198198
[Theory]
@@ -329,5 +329,18 @@ public void Issue2859_LZWPixelStackOverflow<TPixel>(TestImageProvider<TPixel> pr
329329
image.DebugSaveMultiFrame(provider);
330330
image.CompareToReferenceOutputMultiFrame(provider, ImageComparer.Exact);
331331
}
332+
333+
// https://github.com/SixLabors/ImageSharp/issues/2953
334+
[Theory]
335+
[WithFile(TestImages.Gif.Issues.Issue2953, PixelTypes.Rgba32)]
336+
public void Issue2953<TPixel>(TestImageProvider<TPixel> provider)
337+
where TPixel : unmanaged, IPixel<TPixel>
338+
{
339+
// We should throw a InvalidImageContentException when trying to identify or load an invalid GIF file.
340+
var testFile = TestFile.Create(provider.SourceFileOrDescription);
341+
342+
Assert.Throws<InvalidImageContentException>(() => Image.Identify(testFile.FullPath));
343+
Assert.Throws<InvalidImageContentException>(() => Image.Load(testFile.FullPath));
344+
}
332345
}
333346
}

tests/ImageSharp.Tests/TestImages.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -468,6 +468,7 @@ public static class Issues
468468
public const string Issue2758 = "Gif/issues/issue_2758.gif";
469469
public const string Issue2859_A = "Gif/issues/issue_2859_A.gif";
470470
public const string Issue2859_B = "Gif/issues/issue_2859_B.gif";
471+
public const string Issue2953 = "Gif/issues/issue_2953.gif";
471472
}
472473

473474
public static readonly string[] All = { Rings, Giphy, Cheers, Trans, Kumin, Leo, Ratio4x1, Ratio1x4 };
Lines changed: 3 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)