Browse Source

Correctly read and check for iEND chunk

pull/25/head
James Jackson-South 10 years ago
parent
commit
619f683104
  1. 19
      src/ImageSharp/Formats/Png/PngDecoderCore.cs

19
src/ImageSharp/Formats/Png/PngDecoderCore.cs

@ -539,13 +539,8 @@ namespace ImageSharp.Formats
private PngChunk ReadChunk() private PngChunk ReadChunk()
{ {
PngChunk chunk = new PngChunk(); PngChunk chunk = new PngChunk();
this.ReadChunkLength(chunk);
if (this.ReadChunkLength(chunk) == 0) if (chunk.Length < 0)
{
return null;
}
if (chunk.Length <= 0)
{ {
return null; return null;
} }
@ -630,7 +625,7 @@ namespace ImageSharp.Formats
/// <exception cref="ImageFormatException"> /// <exception cref="ImageFormatException">
/// Thrown if the input stream is not valid. /// Thrown if the input stream is not valid.
/// </exception> /// </exception>
private int ReadChunkLength(PngChunk chunk) private void ReadChunkLength(PngChunk chunk)
{ {
int numBytes = this.currentStream.Read(this.chunkLengthBuffer, 0, 4); int numBytes = this.currentStream.Read(this.chunkLengthBuffer, 0, 4);
if (numBytes >= 1 && numBytes <= 3) if (numBytes >= 1 && numBytes <= 3)
@ -638,11 +633,15 @@ namespace ImageSharp.Formats
throw new ImageFormatException("Image stream is not valid!"); throw new ImageFormatException("Image stream is not valid!");
} }
if (numBytes <= 0)
{
chunk.Length = -1;
return;
}
this.chunkLengthBuffer.ReverseBytes(); this.chunkLengthBuffer.ReverseBytes();
chunk.Length = BitConverter.ToInt32(this.chunkLengthBuffer, 0); chunk.Length = BitConverter.ToInt32(this.chunkLengthBuffer, 0);
return numBytes;
} }
} }
} }

Loading…
Cancel
Save