|
|
@ -115,9 +115,9 @@ internal sealed class PngDecoderCore : IImageDecoderInternals |
|
|
private PngChunk? nextChunk; |
|
|
private PngChunk? nextChunk; |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// If true, ADLER32 checksum in the IDAT chunk as well as the chunk CRCs will be ignored.
|
|
|
/// How to handle CRC errors.
|
|
|
/// </summary>
|
|
|
/// </summary>
|
|
|
private bool ignoreCrcErrors; |
|
|
private readonly PngCrcChunkHandling pngCrcChunkHandling; |
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
/// <summary>
|
|
|
/// Initializes a new instance of the <see cref="PngDecoderCore"/> class.
|
|
|
/// Initializes a new instance of the <see cref="PngDecoderCore"/> class.
|
|
|
@ -130,7 +130,7 @@ internal sealed class PngDecoderCore : IImageDecoderInternals |
|
|
this.maxFrames = options.GeneralOptions.MaxFrames; |
|
|
this.maxFrames = options.GeneralOptions.MaxFrames; |
|
|
this.skipMetadata = options.GeneralOptions.SkipMetadata; |
|
|
this.skipMetadata = options.GeneralOptions.SkipMetadata; |
|
|
this.memoryAllocator = this.configuration.MemoryAllocator; |
|
|
this.memoryAllocator = this.configuration.MemoryAllocator; |
|
|
this.ignoreCrcErrors = options.IgnoreCrcCheck; |
|
|
this.pngCrcChunkHandling = options.PngCrcChunkHandling; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
internal PngDecoderCore(PngDecoderOptions options, bool colorMetadataOnly) |
|
|
internal PngDecoderCore(PngDecoderOptions options, bool colorMetadataOnly) |
|
|
@ -141,7 +141,7 @@ internal sealed class PngDecoderCore : IImageDecoderInternals |
|
|
this.skipMetadata = true; |
|
|
this.skipMetadata = true; |
|
|
this.configuration = options.GeneralOptions.Configuration; |
|
|
this.configuration = options.GeneralOptions.Configuration; |
|
|
this.memoryAllocator = this.configuration.MemoryAllocator; |
|
|
this.memoryAllocator = this.configuration.MemoryAllocator; |
|
|
this.ignoreCrcErrors = options.IgnoreCrcCheck; |
|
|
this.pngCrcChunkHandling = options.PngCrcChunkHandling; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
/// <inheritdoc/>
|
|
|
@ -1797,11 +1797,8 @@ internal sealed class PngDecoderCore : IImageDecoderInternals |
|
|
type: type, |
|
|
type: type, |
|
|
data: this.ReadChunkData(length)); |
|
|
data: this.ReadChunkData(length)); |
|
|
|
|
|
|
|
|
if (!this.ignoreCrcErrors) |
|
|
this.ValidateChunk(chunk, buffer); |
|
|
{ |
|
|
|
|
|
this.ValidateChunk(chunk, buffer); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Restore the stream position for IDAT and fdAT chunks, because it will be decoded later and
|
|
|
// Restore the stream position for IDAT and fdAT chunks, because it will be decoded later and
|
|
|
// was only read to verifying the CRC is correct.
|
|
|
// was only read to verifying the CRC is correct.
|
|
|
if (type is PngChunkType.Data or PngChunkType.FrameData) |
|
|
if (type is PngChunkType.Data or PngChunkType.FrameData) |
|
|
@ -1820,8 +1817,7 @@ internal sealed class PngDecoderCore : IImageDecoderInternals |
|
|
private void ValidateChunk(in PngChunk chunk, Span<byte> buffer) |
|
|
private void ValidateChunk(in PngChunk chunk, Span<byte> buffer) |
|
|
{ |
|
|
{ |
|
|
uint inputCrc = this.ReadChunkCrc(buffer); |
|
|
uint inputCrc = this.ReadChunkCrc(buffer); |
|
|
|
|
|
if (chunk.IsCritical(this.pngCrcChunkHandling)) |
|
|
if (chunk.IsCritical) |
|
|
|
|
|
{ |
|
|
{ |
|
|
Span<byte> chunkType = stackalloc byte[4]; |
|
|
Span<byte> chunkType = stackalloc byte[4]; |
|
|
BinaryPrimitives.WriteUInt32BigEndian(chunkType, (uint)chunk.Type); |
|
|
BinaryPrimitives.WriteUInt32BigEndian(chunkType, (uint)chunk.Type); |
|
|
|