Browse Source

Don't backpeddle when reading chunk lengths. Fix #1127

af/octree-no-pixelmap
James Jackson-South 6 years ago
parent
commit
dc39931def
  1. 5
      src/ImageSharp/Formats/Png/PngDecoderCore.cs
  2. 17
      tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs
  3. 1
      tests/ImageSharp.Tests/TestImages.cs
  4. 3
      tests/Images/Input/Png/issues/Issue_1127.png

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

@ -1101,10 +1101,7 @@ namespace SixLabors.ImageSharp.Formats.Png
while (length < 0 || 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;
// Not a valid chunk so try again until we reach a known chunk.
if (!this.TryReadChunkLength(out length))
{
chunk = default;

17
tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs

@ -243,6 +243,23 @@ namespace SixLabors.ImageSharp.Tests.Formats.Png
Assert.Null(ex);
}
[Theory]
[WithFile(TestImages.Png.Issue1127, PixelTypes.Rgba32)]
public void Issue1127<TPixel>(TestImageProvider<TPixel> provider)
where TPixel : struct, IPixel<TPixel>
{
System.Exception ex = Record.Exception(
() =>
{
using (Image<TPixel> image = provider.GetImage(PngDecoder))
{
image.DebugSave(provider);
image.CompareToOriginal(provider, ImageComparer.Exact);
}
});
Assert.Null(ex);
}
[Theory]
[WithFile(TestImages.Png.Splash, PixelTypes.Rgba32)]
[WithFile(TestImages.Png.Bike, PixelTypes.Rgba32)]

1
tests/ImageSharp.Tests/TestImages.cs

@ -90,6 +90,7 @@ namespace SixLabors.ImageSharp.Tests
public const string Issue1014_4 = "Png/issues/Issue_1014_4.png";
public const string Issue1014_5 = "Png/issues/Issue_1014_5.png";
public const string Issue1014_6 = "Png/issues/Issue_1014_6.png";
public const string Issue1127 = "Png/issues/Issue_1127.png";
public static class Bad
{

3
tests/Images/Input/Png/issues/Issue_1127.png

@ -0,0 +1,3 @@
version https://git-lfs.github.com/spec/v1
oid sha256:9913e68387bb596198089315ffd8e01d27356493f78b26add68b5cf37183b239
size 13855
Loading…
Cancel
Save