Browse Source

No need to calculate CRC for non-critical chunks.

pull/1178/head
James Jackson-South 6 years ago
parent
commit
b86ad76bf4
  1. 23
      src/ImageSharp/Formats/Png/PngDecoderCore.cs

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

@ -1141,19 +1141,22 @@ namespace SixLabors.ImageSharp.Formats.Png
/// <param name="chunk">The <see cref="PngChunk"/>.</param>
private void ValidateChunk(in PngChunk chunk)
{
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 && chunk.IsCritical)
{
string chunkTypeName = Encoding.ASCII.GetString(chunkType);
PngThrowHelper.ThrowInvalidChunkCrc(chunkTypeName);
if (this.crc.Value != crc)
{
string chunkTypeName = Encoding.ASCII.GetString(chunkType);
PngThrowHelper.ThrowInvalidChunkCrc(chunkTypeName);
}
}
}

Loading…
Cancel
Save