Skip to content

Commit 9df2631

Browse files
Merge branch 'main' into progressive-jpeg-encoder
2 parents 1349409 + 31a4e10 commit 9df2631

File tree

5 files changed

+25
-13
lines changed

5 files changed

+25
-13
lines changed

src/ImageSharp/Formats/Png/PngDecoderCore.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -210,18 +210,13 @@ public Image<TPixel> Decode<TPixel>(BufferedReadStream stream, CancellationToken
210210
break;
211211
case PngChunkType.FrameControl:
212212
frameCount++;
213-
if (frameCount == this.maxFrames)
214-
{
215-
break;
216-
}
217-
218213
currentFrame = null;
219214
currentFrameControl = this.ReadFrameControlChunk(chunk.Data.GetSpan());
220215
break;
221216
case PngChunkType.FrameData:
222-
if (frameCount == this.maxFrames)
217+
if (frameCount >= this.maxFrames)
223218
{
224-
break;
219+
goto EOF;
225220
}
226221

227222
if (image is null)
@@ -277,6 +272,11 @@ public Image<TPixel> Decode<TPixel>(BufferedReadStream stream, CancellationToken
277272
previousFrameControl = currentFrameControl;
278273
}
279274

275+
if (frameCount >= this.maxFrames)
276+
{
277+
goto EOF;
278+
}
279+
280280
break;
281281
case PngChunkType.Palette:
282282
this.palette = chunk.Data.GetSpan().ToArray();
@@ -396,7 +396,7 @@ public ImageInfo Identify(BufferedReadStream stream, CancellationToken cancellat
396396
break;
397397
case PngChunkType.FrameControl:
398398
++frameCount;
399-
if (frameCount == this.maxFrames)
399+
if (frameCount >= this.maxFrames)
400400
{
401401
break;
402402
}
@@ -405,7 +405,7 @@ public ImageInfo Identify(BufferedReadStream stream, CancellationToken cancellat
405405

406406
break;
407407
case PngChunkType.FrameData:
408-
if (frameCount == this.maxFrames)
408+
if (frameCount >= this.maxFrames)
409409
{
410410
break;
411411
}

src/ImageSharp/Formats/Webp/WebpChunkParsingUtils.cs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -218,10 +218,6 @@ public static WebpImageInfo ReadVp8XHeader(BufferedReadStream stream, Span<byte>
218218

219219
// 3 reserved bytes should follow which are supposed to be zero.
220220
stream.Read(buffer, 0, 3);
221-
if (buffer[0] != 0 || buffer[1] != 0 || buffer[2] != 0)
222-
{
223-
WebpThrowHelper.ThrowImageFormatException("reserved bytes should be zero");
224-
}
225221

226222
// 3 bytes for the width.
227223
uint width = ReadUInt24LittleEndian(stream, buffer) + 1;

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)