Browse Source
Merge pull request #2773 from SixLabors/js/v4-2769
V4 Correctly break during Png decoding
pull/2778/head
James Jackson-South
2 years ago
committed by
GitHub
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with
25 additions and
13 deletions
-
src/ImageSharp/Formats/Png/PngDecoderCore.cs
-
src/ImageSharp/Formats/Webp/WebpChunkParsingUtils.cs
-
tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs
-
tests/ImageSharp.Tests/TestImages.cs
-
tests/Images/Input/Png/issues/Issue_2752.png
|
|
|
@ -210,18 +210,13 @@ internal sealed class PngDecoderCore : IImageDecoderInternals |
|
|
|
break; |
|
|
|
case PngChunkType.FrameControl: |
|
|
|
frameCount++; |
|
|
|
if (frameCount == this.maxFrames) |
|
|
|
{ |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
currentFrame = null; |
|
|
|
currentFrameControl = this.ReadFrameControlChunk(chunk.Data.GetSpan()); |
|
|
|
break; |
|
|
|
case PngChunkType.FrameData: |
|
|
|
if (frameCount == this.maxFrames) |
|
|
|
if (frameCount >= this.maxFrames) |
|
|
|
{ |
|
|
|
break; |
|
|
|
goto EOF; |
|
|
|
} |
|
|
|
|
|
|
|
if (image is null) |
|
|
|
@ -277,6 +272,11 @@ internal sealed class PngDecoderCore : IImageDecoderInternals |
|
|
|
previousFrameControl = currentFrameControl; |
|
|
|
} |
|
|
|
|
|
|
|
if (frameCount >= this.maxFrames) |
|
|
|
{ |
|
|
|
goto EOF; |
|
|
|
} |
|
|
|
|
|
|
|
break; |
|
|
|
case PngChunkType.Palette: |
|
|
|
this.palette = chunk.Data.GetSpan().ToArray(); |
|
|
|
@ -396,7 +396,7 @@ internal sealed class PngDecoderCore : IImageDecoderInternals |
|
|
|
break; |
|
|
|
case PngChunkType.FrameControl: |
|
|
|
++frameCount; |
|
|
|
if (frameCount == this.maxFrames) |
|
|
|
if (frameCount >= this.maxFrames) |
|
|
|
{ |
|
|
|
break; |
|
|
|
} |
|
|
|
@ -405,7 +405,7 @@ internal sealed class PngDecoderCore : IImageDecoderInternals |
|
|
|
|
|
|
|
break; |
|
|
|
case PngChunkType.FrameData: |
|
|
|
if (frameCount == this.maxFrames) |
|
|
|
if (frameCount >= this.maxFrames) |
|
|
|
{ |
|
|
|
break; |
|
|
|
} |
|
|
|
|
|
|
|
@ -218,10 +218,6 @@ internal static class WebpChunkParsingUtils |
|
|
|
|
|
|
|
// 3 reserved bytes should follow which are supposed to be zero.
|
|
|
|
stream.Read(buffer, 0, 3); |
|
|
|
if (buffer[0] != 0 || buffer[1] != 0 || buffer[2] != 0) |
|
|
|
{ |
|
|
|
WebpThrowHelper.ThrowImageFormatException("reserved bytes should be zero"); |
|
|
|
} |
|
|
|
|
|
|
|
// 3 bytes for the width.
|
|
|
|
uint width = ReadUInt24LittleEndian(stream, buffer) + 1; |
|
|
|
|
|
|
|
@ -701,4 +701,14 @@ public partial class PngDecoderTests |
|
|
|
string path = Path.GetFullPath(Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, file)); |
|
|
|
using Image image = Image.Load(path); |
|
|
|
} |
|
|
|
|
|
|
|
[Theory] |
|
|
|
[WithFile(TestImages.Png.Issue2752, PixelTypes.Rgba32)] |
|
|
|
public void CanDecodeJustOneFrame<TPixel>(TestImageProvider<TPixel> provider) |
|
|
|
where TPixel : unmanaged, IPixel<TPixel> |
|
|
|
{ |
|
|
|
DecoderOptions options = new() { MaxFrames = 1 }; |
|
|
|
using Image<TPixel> image = provider.GetImage(PngDecoder.Instance, options); |
|
|
|
Assert.Equal(1, image.Frames.Count); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
@ -156,6 +156,9 @@ public static class TestImages |
|
|
|
// Issue 2668: https://github.com/SixLabors/ImageSharp/issues/2668
|
|
|
|
public const string Issue2668 = "Png/issues/Issue_2668.png"; |
|
|
|
|
|
|
|
// Issue 2752: https://github.com/SixLabors/ImageSharp/issues/2752
|
|
|
|
public const string Issue2752 = "Png/issues/Issue_2752.png"; |
|
|
|
|
|
|
|
public static class Bad |
|
|
|
{ |
|
|
|
public const string MissingDataChunk = "Png/xdtn0g01.png"; |
|
|
|
|
|
|
|
@ -0,0 +1,3 @@ |
|
|
|
version https://git-lfs.github.com/spec/v1 |
|
|
|
oid sha256:2d4cb44eea721009c616de30a1f18c1de59635de4b313b13d685456a529ced97 |
|
|
|
size 5590983 |