Browse Source

Always read CRC.

pull/1178/head
James Jackson-South 6 years ago
parent
commit
ccbb6d95f6
  1. 7
      src/ImageSharp/Formats/Png/PngDecoderCore.cs
  2. 23
      tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs
  3. 4
      tests/ImageSharp.Tests/TestImages.cs
  4. BIN
      tests/Images/Input/Png/issues/Issue_1177_1.png
  5. BIN
      tests/Images/Input/Png/issues/Issue_1177_2.png

7
src/ImageSharp/Formats/Png/PngDecoderCore.cs

@ -1141,11 +1141,6 @@ namespace SixLabors.ImageSharp.Formats.Png
/// <param name="chunk">The <see cref="PngChunk"/>.</param>
private void ValidateChunk(in PngChunk chunk)
{
if (!chunk.IsCritical)
{
return;
}
Span<byte> 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);

23
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<TPixel>(TestImageProvider<TPixel> provider)
@ -243,6 +249,23 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png
Assert.Null(ex);
}
[Theory]
[WithFileCollection(nameof(TestImagesIssue1177), PixelTypes.Rgba32)]
public void Issue1177<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : unmanaged, IPixel<TPixel>
{
System.Exception ex = Record.Exception(
() =>
{
using (Image<TPixel> 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<TPixel>(TestImageProvider<TPixel> provider)

4
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

BIN
tests/Images/Input/Png/issues/Issue_1177_1.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

BIN
tests/Images/Input/Png/issues/Issue_1177_2.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 56 KiB

Loading…
Cancel
Save