diff --git a/src/ImageSharp/Formats/Png/PngDecoderCore.cs b/src/ImageSharp/Formats/Png/PngDecoderCore.cs index 2701bd2a7..076230c0b 100644 --- a/src/ImageSharp/Formats/Png/PngDecoderCore.cs +++ b/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; diff --git a/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs b/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs index bf767e811..7fdafafa8 100644 --- a/tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs +++ b/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(TestImageProvider provider) + where TPixel : struct, IPixel + { + System.Exception ex = Record.Exception( + () => + { + using (Image 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)] diff --git a/tests/ImageSharp.Tests/TestImages.cs b/tests/ImageSharp.Tests/TestImages.cs index b1cfec218..2e58ac970 100644 --- a/tests/ImageSharp.Tests/TestImages.cs +++ b/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 { diff --git a/tests/Images/Input/Png/issues/Issue_1127.png b/tests/Images/Input/Png/issues/Issue_1127.png new file mode 100644 index 000000000..6101102e5 --- /dev/null +++ b/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