From 48b45a4791847c090f4c7e423fbcbf80a1944846 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Tue, 15 Nov 2016 23:19:21 +1100 Subject: [PATCH] Reuse Crc --- src/ImageSharp/Formats/Png/PngDecoderCore.cs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs index f31af2b49d..4d581b2b6e 100644 --- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs @@ -44,6 +44,11 @@ namespace ImageSharp.Formats /// private readonly char[] chars = new char[4]; + /// + /// Reusable crc for validating chunks. + /// + private readonly Crc32 crc = new Crc32(); + /// /// The stream to decode from. /// @@ -594,11 +599,11 @@ namespace ImageSharp.Formats chunk.Crc = BitConverter.ToUInt32(this.crcBuffer, 0); - Crc32 crc = new Crc32(); - crc.Update(this.chunkTypeBuffer); - crc.Update(chunk.Data, 0, chunk.Length); + this.crc.Reset(); + this.crc.Update(this.chunkTypeBuffer); + this.crc.Update(chunk.Data, 0, chunk.Length); - if (crc.Value != chunk.Crc) + if (this.crc.Value != chunk.Crc) { throw new ImageFormatException("CRC Error. PNG Image chunk is corrupt!"); }