Skip to content

Commit 53cf942

Browse files
Merge branch 'release/3.1.x' into js/mono-aot-decoder-workaround
2 parents 9840a23 + d7ef0e2 commit 53cf942

File tree

4 files changed

+25
-9
lines changed

4 files changed

+25
-9
lines changed

src/ImageSharp/Formats/Png/PngDecoderCore.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -197,18 +197,13 @@ protected override Image<TPixel> Decode<TPixel>(BufferedReadStream stream, Cance
197197
break;
198198
case PngChunkType.FrameControl:
199199
frameCount++;
200-
if (frameCount == this.maxFrames)
201-
{
202-
break;
203-
}
204-
205200
currentFrame = null;
206201
currentFrameControl = this.ReadFrameControlChunk(chunk.Data.GetSpan());
207202
break;
208203
case PngChunkType.FrameData:
209-
if (frameCount == this.maxFrames)
204+
if (frameCount >= this.maxFrames)
210205
{
211-
break;
206+
goto EOF;
212207
}
213208

214209
if (image is null)
@@ -264,6 +259,11 @@ protected override Image<TPixel> Decode<TPixel>(BufferedReadStream stream, Cance
264259
previousFrameControl = currentFrameControl;
265260
}
266261

262+
if (frameCount >= this.maxFrames)
263+
{
264+
goto EOF;
265+
}
266+
267267
break;
268268
case PngChunkType.Palette:
269269
this.palette = chunk.Data.GetSpan().ToArray();
@@ -382,15 +382,15 @@ protected override ImageInfo Identify(BufferedReadStream stream, CancellationTok
382382
break;
383383
case PngChunkType.FrameControl:
384384
++frameCount;
385-
if (frameCount == this.maxFrames)
385+
if (frameCount >= this.maxFrames)
386386
{
387387
break;
388388
}
389389

390390
lastFrameControl = this.ReadFrameControlChunk(chunk.Data.GetSpan());
391391
break;
392392
case PngChunkType.FrameData:
393-
if (frameCount == this.maxFrames)
393+
if (frameCount >= this.maxFrames)
394394
{
395395
break;
396396
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,4 +701,14 @@ public void Decode_BadPalette(string file)
701701
string path = Path.GetFullPath(Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, file));
702702
using Image image = Image.Load(path);
703703
}
704+
705+
[Theory]
706+
[WithFile(TestImages.Png.Issue2752, PixelTypes.Rgba32)]
707+
public void CanDecodeJustOneFrame<TPixel>(TestImageProvider<TPixel> provider)
708+
where TPixel : unmanaged, IPixel<TPixel>
709+
{
710+
DecoderOptions options = new() { MaxFrames = 1 };
711+
using Image<TPixel> image = provider.GetImage(PngDecoder.Instance, options);
712+
Assert.Equal(1, image.Frames.Count);
713+
}
704714
}

tests/ImageSharp.Tests/TestImages.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ public static class Png
156156
// Issue 2668: https://github.com/SixLabors/ImageSharp/issues/2668
157157
public const string Issue2668 = "Png/issues/Issue_2668.png";
158158

159+
// Issue 2752: https://github.com/SixLabors/ImageSharp/issues/2752
160+
public const string Issue2752 = "Png/issues/Issue_2752.png";
161+
159162
public static class Bad
160163
{
161164
public const string MissingDataChunk = "Png/xdtn0g01.png";
Lines changed: 3 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)