Browse Source
Merge pull request #1178 from SixLabors/js/fix-1177
Always read CRC.
pull/1180/head
James Jackson-South
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with
40 additions and
15 deletions
-
src/ImageSharp/Formats/Png/PngDecoderCore.cs
-
tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs
-
tests/ImageSharp.Tests/TestImages.cs
-
BIN
tests/Images/Input/Png/issues/Issue_1177_1.png
-
BIN
tests/Images/Input/Png/issues/Issue_1177_2.png
|
|
|
@ -1141,24 +1141,22 @@ 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]; |
|
|
|
uint crc = this.ReadChunkCrc(); |
|
|
|
|
|
|
|
BinaryPrimitives.WriteUInt32BigEndian(chunkType, (uint)chunk.Type); |
|
|
|
if (chunk.IsCritical) |
|
|
|
{ |
|
|
|
Span<byte> chunkType = stackalloc byte[4]; |
|
|
|
BinaryPrimitives.WriteUInt32BigEndian(chunkType, (uint)chunk.Type); |
|
|
|
|
|
|
|
this.crc.Reset(); |
|
|
|
this.crc.Update(chunkType); |
|
|
|
this.crc.Update(chunk.Data.GetSpan()); |
|
|
|
this.crc.Reset(); |
|
|
|
this.crc.Update(chunkType); |
|
|
|
this.crc.Update(chunk.Data.GetSpan()); |
|
|
|
|
|
|
|
uint crc = this.ReadChunkCrc(); |
|
|
|
if (this.crc.Value != crc) |
|
|
|
{ |
|
|
|
string chunkTypeName = Encoding.ASCII.GetString(chunkType); |
|
|
|
PngThrowHelper.ThrowInvalidChunkCrc(chunkTypeName); |
|
|
|
if (this.crc.Value != crc) |
|
|
|
{ |
|
|
|
string chunkTypeName = Encoding.ASCII.GetString(chunkType); |
|
|
|
PngThrowHelper.ThrowInvalidChunkCrc(chunkTypeName); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -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) |
|
|
|
|
|
|
|
@ -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
|
|
|
|
|
Width:
|
Height:
|
Size: 6.9 KiB
|
Width:
|
Height:
|
Size: 56 KiB
|