diff --git a/Directory.Build.props b/Directory.Build.props
index b46c0f19f2..524cf27890 100644
--- a/Directory.Build.props
+++ b/Directory.Build.props
@@ -33,4 +33,13 @@
true
+
+
+
+
+ https://api.nuget.org/v3/index.json;
+ https://f.feedz.io/sixlabors/sixlabors/nuget/index.json;
+ https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-eng/nuget/v3/index.json;
+
+
diff --git a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs
index 8fdaef9e0f..886f667e4c 100644
--- a/src/ImageSharp/Formats/Gif/GifDecoderCore.cs
+++ b/src/ImageSharp/Formats/Gif/GifDecoderCore.cs
@@ -402,6 +402,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");
+ }
+
if (this.skipMetadata)
{
stream.Seek(length, SeekOrigin.Current);
diff --git a/tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs
index 4e42722d2c..124a2688a3 100644
--- a/tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs
+++ b/tests/ImageSharp.Tests/Formats/Gif/GifDecoderTests.cs
@@ -183,16 +183,16 @@ public void Issue1530_BadDescriptorDimensions(TestImageProvider
image.CompareToReferenceOutputMultiFrame(provider, ImageComparer.Exact);
}
- // https://github.com/SixLabors/ImageSharp/issues/2758
- [Theory]
- [WithFile(TestImages.Gif.Issues.Issue2758, PixelTypes.Rgba32)]
- public void Issue2758_BadDescriptorDimensions(TestImageProvider provider)
- where TPixel : unmanaged, IPixel
- {
- using Image image = provider.GetImage();
- image.DebugSaveMultiFrame(provider);
- image.CompareToReferenceOutputMultiFrame(provider, ImageComparer.Exact);
- }
+ // https://github.com/SixLabors/ImageSharp/issues/2758
+ [Theory]
+ [WithFile(TestImages.Gif.Issues.Issue2758, PixelTypes.Rgba32)]
+ public void Issue2758_BadDescriptorDimensions(TestImageProvider provider)
+ where TPixel : unmanaged, IPixel
+ {
+ using Image image = provider.GetImage();
+ image.DebugSaveMultiFrame(provider);
+ image.CompareToReferenceOutputMultiFrame(provider, ImageComparer.Exact);
+ }
// https://github.com/SixLabors/ImageSharp/issues/405
[Theory]
@@ -329,5 +329,18 @@ public void Issue2859_LZWPixelStackOverflow(TestImageProvider 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(TestImageProvider provider)
+ where TPixel : unmanaged, IPixel
+ {
+ // We should throw a InvalidImageContentException when trying to identify or load an invalid GIF file.
+ var testFile = TestFile.Create(provider.SourceFileOrDescription);
+
+ Assert.Throws(() => Image.Identify(testFile.FullPath));
+ Assert.Throws(() => Image.Load(testFile.FullPath));
+ }
}
}
diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs
index 9ee63e5636..9210be394e 100644
--- a/tests/ImageSharp.Tests/TestImages.cs
+++ b/tests/ImageSharp.Tests/TestImages.cs
@@ -468,6 +468,7 @@ public static class Issues
public const string Issue2758 = "Gif/issues/issue_2758.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[] All = { Rings, Giphy, Cheers, Trans, Kumin, Leo, Ratio4x1, Ratio1x4 };
diff --git a/tests/Images/Input/Gif/issues/issue_2953.gif b/tests/Images/Input/Gif/issues/issue_2953.gif
new file mode 100644
index 0000000000..98c06e5c58
--- /dev/null
+++ b/tests/Images/Input/Gif/issues/issue_2953.gif
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:4fa4a002b264a41677cc10f115f3572111852993a53ee8cea5f4ec0bf8dec195
+size 40