Browse Source
Merge pull request #1128 from SixLabors/js/fix-1127
Don't backpeddle when reading chunk lengths. Fix #1127
pull/1131/head
James Jackson-South
6 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with
19 additions and
4 deletions
-
src/ImageSharp/Formats/Png/PngDecoderCore.cs
-
tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs
-
tests/ImageSharp.Tests/TestImages.cs
-
BIN
tests/Images/Input/Png/issues/Issue_1127.png
|
|
|
@ -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; |
|
|
|
|
|
|
|
@ -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)] |
|
|
|
|
|
|
|
@ -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 |
|
|
|
{ |
|
|
|
|
Width:
|
Height:
|
Size: 14 KiB
|