Browse Source

Handle corrupted data portions. Fix #358

pull/359/head
James Jackson-South 9 years ago
parent
commit
bfc90878ba
  1. 13
      src/ImageSharp/Formats/Png/PngDecoderCore.cs
  2. 1
      tests/ImageSharp.Tests/TestImages.cs
  3. BIN
      tests/Images/Input/Png/big-corrupted-chunk.png

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

@ -1124,12 +1124,23 @@ namespace SixLabors.ImageSharp.Formats.Png
{
var chunk = new PngChunk();
this.ReadChunkLength(chunk);
if (chunk.Length < 0)
if (chunk.Length == -1)
{
// IEND
return null;
}
if (chunk.Length < 0 || chunk.Length > this.currentStream.Length - this.currentStream.Position)
{
// Not a valid chunk so we skip back all but one of the four bytes we have just read.
// That lets us read one byte at a time until we reach a known chunk.
this.currentStream.Position -= 3;
return chunk;
}
this.ReadChunkType(chunk);
if (chunk.Type == PngChunkTypes.Data)
{
return chunk;

1
tests/ImageSharp.Tests/TestImages.cs

@ -20,6 +20,7 @@ namespace SixLabors.ImageSharp.Tests
public const string Blur = "Png/blur.png";
public const string Indexed = "Png/indexed.png";
public const string Splash = "Png/splash.png";
public const string CorruptedChunk = "Png/big-corrupted-chunk.png";
public const string Cross = "Png/cross.png";
public const string Powerpoint = "Png/pp.png";
public const string SplashInterlaced = "Png/splash-interlaced.png";

BIN
tests/Images/Input/Png/big-corrupted-chunk.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.0 KiB

Loading…
Cancel
Save