From 619f683104ebcdd19a0cd175d4928a4a97ef04f8 Mon Sep 17 00:00:00 2001 From: James Jackson-South Date: Fri, 11 Nov 2016 17:22:46 +1100 Subject: [PATCH] Correctly read and check for iEND chunk --- src/ImageSharp/Formats/Png/PngDecoderCore.cs | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs index 186e99437..ce2d28ff0 100644 --- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs +++ b/src/ImageSharp/Formats/Png/PngDecoderCore.cs @@ -539,13 +539,8 @@ namespace ImageSharp.Formats private PngChunk ReadChunk() { PngChunk chunk = new PngChunk(); - - if (this.ReadChunkLength(chunk) == 0) - { - return null; - } - - if (chunk.Length <= 0) + this.ReadChunkLength(chunk); + if (chunk.Length < 0) { return null; } @@ -630,7 +625,7 @@ namespace ImageSharp.Formats /// /// Thrown if the input stream is not valid. /// - private int ReadChunkLength(PngChunk chunk) + private void ReadChunkLength(PngChunk chunk) { int numBytes = this.currentStream.Read(this.chunkLengthBuffer, 0, 4); if (numBytes >= 1 && numBytes <= 3) @@ -638,11 +633,15 @@ namespace ImageSharp.Formats throw new ImageFormatException("Image stream is not valid!"); } + if (numBytes <= 0) + { + chunk.Length = -1; + return; + } + this.chunkLengthBuffer.ReverseBytes(); chunk.Length = BitConverter.ToInt32(this.chunkLengthBuffer, 0); - - return numBytes; } } }