diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs
index bc7b9d815..e2cd80631 100644
--- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs
+++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs
@@ -1141,11 +1141,6 @@ namespace SixLabors.ImageSharp.Formats.Png
/// The .
private void ValidateChunk(in PngChunk chunk)
{
- if (!chunk.IsCritical)
- {
- return;
- }
-
Span chunkType = stackalloc byte[4];
BinaryPrimitives.WriteUInt32BigEndian(chunkType, (uint)chunk.Type);
@@ -1155,7 +1150,7 @@ namespace SixLabors.ImageSharp.Formats.Png
this.crc.Update(chunk.Data.GetSpan());
uint crc = this.ReadChunkCrc();
- if (this.crc.Value != crc)
+ if (this.crc.Value != crc && chunk.IsCritical)
{
string chunkTypeName = Encoding.ASCII.GetString(chunkType);
PngThrowHelper.ThrowInvalidChunkCrc(chunkTypeName);
diff --git a/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs
index 46112bdd8..b08025f53 100644
--- a/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs
+++ b/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs
@@ -89,6 +89,12 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png
TestImages.Png.Issue1014_5, TestImages.Png.Issue1014_6
};
+ public static readonly string[] TestImagesIssue1177 =
+ {
+ TestImages.Png.Issue1177_1,
+ TestImages.Png.Issue1177_2
+ };
+
[Theory]
[WithFileCollection(nameof(CommonTestImages), PixelTypes.Rgba32)]
public void Decode(TestImageProvider provider)
@@ -243,6 +249,23 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png
Assert.Null(ex);
}
+ [Theory]
+ [WithFileCollection(nameof(TestImagesIssue1177), PixelTypes.Rgba32)]
+ public void Issue1177(TestImageProvider provider)
+ where TPixel : unmanaged, IPixel
+ {
+ System.Exception ex = Record.Exception(
+ () =>
+ {
+ using (Image image = provider.GetImage(PngDecoder))
+ {
+ image.DebugSave(provider);
+ image.CompareToOriginal(provider, ImageComparer.Exact);
+ }
+ });
+ Assert.Null(ex);
+ }
+
[Theory]
[WithFile(TestImages.Png.Issue1127, PixelTypes.Rgba32)]
public void Issue1127(TestImageProvider provider)
diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs
index 65d975257..18fd84331 100644
--- a/tests/ImageSharp.Tests/TestImages.cs
+++ b/tests/ImageSharp.Tests/TestImages.cs
@@ -95,6 +95,10 @@ namespace SixLabors.ImageSharp.Tests
public const string Issue1014_6 = "Png/issues/Issue_1014_6.png";
public const string Issue1127 = "Png/issues/Issue_1127.png";
+ // Issue 1177: https://github.com/SixLabors/ImageSharp/issues/1177
+ public const string Issue1177_1 = "Png/issues/Issue_1177_1.png";
+ public const string Issue1177_2 = "Png/issues/Issue_1177_2.png";
+
public static class Bad
{
// Odd chunk lengths
diff --git a/tests/Images/Input/Png/issues/Issue_1177_1.png b/tests/Images/Input/Png/issues/Issue_1177_1.png
new file mode 100644
index 000000000..2d851e31b
--- /dev/null
+++ b/tests/Images/Input/Png/issues/Issue_1177_1.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:cef2be6012f4604f9f30b51273661058df0201be4de508235f372eb2304b2132
+size 7023
diff --git a/tests/Images/Input/Png/issues/Issue_1177_2.png b/tests/Images/Input/Png/issues/Issue_1177_2.png
new file mode 100644
index 000000000..efd043b38
--- /dev/null
+++ b/tests/Images/Input/Png/issues/Issue_1177_2.png
@@ -0,0 +1,3 @@
+version https://git-lfs.github.com/spec/v1
+oid sha256:7067af724977e1ecd8fc761f50226eaaa9e9d4142be963b4edbbf0918b8eba1d
+size 57125