Skip to content

Commit

Permalink
Merge branch 'main' into progressive-jpeg-encoder
Browse files Browse the repository at this point in the history
  • Loading branch information
JimBobSquarePants committed Jul 16, 2024
2 parents 1349409 + 31a4e10 commit 9df2631
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 13 deletions.
18 changes: 9 additions & 9 deletions src/ImageSharp/Formats/Png/PngDecoderCore.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,18 +210,13 @@ public Image<TPixel> Decode<TPixel>(BufferedReadStream stream, CancellationToken
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)
Expand Down Expand Up @@ -277,6 +272,11 @@ public Image<TPixel> Decode<TPixel>(BufferedReadStream stream, CancellationToken
previousFrameControl = currentFrameControl;
}

if (frameCount >= this.maxFrames)
{
goto EOF;
}

break;
case PngChunkType.Palette:
this.palette = chunk.Data.GetSpan().ToArray();
Expand Down Expand Up @@ -396,7 +396,7 @@ public ImageInfo Identify(BufferedReadStream stream, CancellationToken cancellat
break;
case PngChunkType.FrameControl:
++frameCount;
if (frameCount == this.maxFrames)
if (frameCount >= this.maxFrames)
{
break;
}
Expand All @@ -405,7 +405,7 @@ public ImageInfo Identify(BufferedReadStream stream, CancellationToken cancellat

break;
case PngChunkType.FrameData:
if (frameCount == this.maxFrames)
if (frameCount >= this.maxFrames)
{
break;
}
Expand Down
4 changes: 0 additions & 4 deletions src/ImageSharp/Formats/Webp/WebpChunkParsingUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,6 @@ public static WebpImageInfo ReadVp8XHeader(BufferedReadStream stream, Span<byte>

// 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;
Expand Down
10 changes: 10 additions & 0 deletions tests/ImageSharp.Tests/Formats/Png/PngDecoderTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -701,4 +701,14 @@ public void Decode_BadPalette(string file)
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);
}
}
3 changes: 3 additions & 0 deletions tests/ImageSharp.Tests/TestImages.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ public static class Png
// 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";
Expand Down
3 changes: 3 additions & 0 deletions tests/Images/Input/Png/issues/Issue_2752.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 9df2631

Please sign in to comment.