@@ -115,9 +115,9 @@ internal sealed class PngDecoderCore : IImageDecoderInternals
115115 private PngChunk ? nextChunk ;
116116
117117 /// <summary>
118- /// If true, ADLER32 checksum in the IDAT chunk as well as the chunk CRCs will be ignored .
118+ /// How to handle CRC errors .
119119 /// </summary>
120- private bool ignoreCrcErrors ;
120+ private readonly PngCrcChunkHandling pngCrcChunkHandling ;
121121
122122 /// <summary>
123123 /// Initializes a new instance of the <see cref="PngDecoderCore"/> class.
@@ -130,7 +130,7 @@ public PngDecoderCore(PngDecoderOptions options)
130130 this . maxFrames = options . GeneralOptions . MaxFrames ;
131131 this . skipMetadata = options . GeneralOptions . SkipMetadata ;
132132 this . memoryAllocator = this . configuration . MemoryAllocator ;
133- this . ignoreCrcErrors = options . IgnoreCrcCheck ;
133+ this . pngCrcChunkHandling = options . PngCrcChunkHandling ;
134134 }
135135
136136 internal PngDecoderCore ( PngDecoderOptions options , bool colorMetadataOnly )
@@ -141,7 +141,7 @@ internal PngDecoderCore(PngDecoderOptions options, bool colorMetadataOnly)
141141 this . skipMetadata = true ;
142142 this . configuration = options . GeneralOptions . Configuration ;
143143 this . memoryAllocator = this . configuration . MemoryAllocator ;
144- this . ignoreCrcErrors = options . IgnoreCrcCheck ;
144+ this . pngCrcChunkHandling = options . PngCrcChunkHandling ;
145145 }
146146
147147 /// <inheritdoc/>
@@ -1797,11 +1797,8 @@ private bool TryReadChunk(Span<byte> buffer, out PngChunk chunk)
17971797 type : type ,
17981798 data : this . ReadChunkData ( length ) ) ;
17991799
1800- if ( ! this . ignoreCrcErrors )
1801- {
1802- this . ValidateChunk ( chunk , buffer ) ;
1803- }
1804-
1800+ this . ValidateChunk ( chunk , buffer ) ;
1801+
18051802 // Restore the stream position for IDAT and fdAT chunks, because it will be decoded later and
18061803 // was only read to verifying the CRC is correct.
18071804 if ( type is PngChunkType . Data or PngChunkType . FrameData )
@@ -1820,8 +1817,7 @@ private bool TryReadChunk(Span<byte> buffer, out PngChunk chunk)
18201817 private void ValidateChunk ( in PngChunk chunk , Span < byte > buffer )
18211818 {
18221819 uint inputCrc = this . ReadChunkCrc ( buffer ) ;
1823-
1824- if ( chunk . IsCritical )
1820+ if ( chunk . IsCritical ( this . pngCrcChunkHandling ) )
18251821 {
18261822 Span < byte > chunkType = stackalloc byte [ 4 ] ;
18271823 BinaryPrimitives . WriteUInt32BigEndian ( chunkType , ( uint ) chunk . Type ) ;
0 commit comments