Browse Source

Fix #127

Stop processing once we hit the end marker.
af/merge-core
James Jackson-South 9 years ago
parent
commit
0b08485708
  1. 16
      src/ImageSharp.Formats.Png/PngDecoderCore.cs

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

@ -109,6 +109,11 @@ namespace ImageSharp.Formats
/// </summary>
private byte[] paletteAlpha;
/// <summary>
/// A value indicating whether the end chunk has been reached.
/// </summary>
private bool isEndChunkReached;
/// <summary>
/// Initializes static members of the <see cref="PngDecoderCore"/> class.
/// </summary>
@ -158,18 +163,11 @@ namespace ImageSharp.Formats
this.currentStream = stream;
this.currentStream.Skip(8);
bool isEndChunkReached = false;
using (MemoryStream dataStream = new MemoryStream())
{
PngChunk currentChunk;
while ((currentChunk = this.ReadChunk()) != null)
while (!this.isEndChunkReached && (currentChunk = this.ReadChunk()) != null)
{
if (isEndChunkReached)
{
throw new ImageFormatException("Image does not end with end chunk.");
}
try
{
switch (currentChunk.Type)
@ -199,7 +197,7 @@ namespace ImageSharp.Formats
this.ReadTextChunk(currentImage, currentChunk.Data, currentChunk.Length);
break;
case PngChunkTypes.End:
isEndChunkReached = true;
this.isEndChunkReached = true;
break;
}
}

Loading…
Cancel
Save