private void ReadChunkCrc(PngChunk chunk, byte[] typeBuffer) { byte[] crcBuffer = new byte[4]; int numBytes = currentStream.Read(crcBuffer, 0, 4); if (numBytes >= 1 && numBytes <= 3) { throw new Exception("Image stream is not valid!"); } Array.Reverse(crcBuffer); chunk.Crc = BitConverter.ToUInt32(crcBuffer, 0); Crc32 crc = new Crc32(); crc.Update(typeBuffer); crc.Update(chunk.Data); if (crc.Value != chunk.Crc) { throw new Exception("CRC Error. Png Image chunk is corrupt!"); } }
private void ReadChunkData(PngChunk chunk) { chunk.Data = new byte[chunk.Length]; currentStream.Read(chunk.Data, 0, chunk.Length); }