Skip to content

Commit f85500d

Browse files
Merge pull request #2675 from SixLabors/js/v3-fixes
Add v3.1.x fixes #2673 and #2674 into main.
2 parents 965335c + daad307 commit f85500d

File tree

5 files changed

+20
-4
lines changed

5 files changed

+20
-4
lines changed

src/ImageSharp/Formats/Png/PngDecoderCore.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1874,8 +1874,13 @@ private bool TryReadChunk(Span<byte> buffer, out PngChunk chunk)
18741874
PngChunkType type = this.ReadChunkType(buffer);
18751875

18761876
// If we're reading color metadata only we're only interested in the IHDR and tRNS chunks.
1877-
// We can skip all other chunk data in the stream for better performance.
1878-
if (this.colorMetadataOnly && type != PngChunkType.Header && type != PngChunkType.Transparency && type != PngChunkType.Palette)
1877+
// We can skip most other chunk data in the stream for better performance.
1878+
if (this.colorMetadataOnly &&
1879+
type != PngChunkType.Header &&
1880+
type != PngChunkType.Transparency &&
1881+
type != PngChunkType.Palette &&
1882+
type != PngChunkType.AnimationControl &&
1883+
type != PngChunkType.FrameControl)
18791884
{
18801885
chunk = new PngChunk(length, type);
18811886
return true;

src/ImageSharp/Processing/Processors/Drawing/DrawImageProcessor{TPixelBg,TPixelFg}.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,10 @@ protected override void OnFrameApply(ImageFrame<TPixelBg> source)
9898
top = 0;
9999
}
100100

101-
// clamp the height/width to the availible space left to prevent overflowing
101+
// Clamp the height/width to the available space left to prevent overflowing
102102
foregroundRectangle.Width = Math.Min(source.Width - left, foregroundRectangle.Width);
103103
foregroundRectangle.Height = Math.Min(source.Height - top, foregroundRectangle.Height);
104+
foregroundRectangle = Rectangle.Intersect(foregroundRectangle, this.ForegroundImage.Bounds);
104105

105106
int width = foregroundRectangle.Width;
106107
int height = foregroundRectangle.Height;
@@ -111,7 +112,6 @@ protected override void OnFrameApply(ImageFrame<TPixelBg> source)
111112
}
112113

113114
// Sanitize the dimensions so that we don't try and sample outside the image.
114-
foregroundRectangle = Rectangle.Intersect(foregroundRectangle, this.ForegroundImage.Bounds);
115115
Rectangle backgroundRectangle = Rectangle.Intersect(new(left, top, width, height), this.SourceRectangle);
116116
Configuration configuration = this.Configuration;
117117

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -665,4 +665,11 @@ public void Binary_PrematureEof()
665665
Assert.True(eofHitCounter.EofHitCount <= 3);
666666
Assert.Equal(new Size(200, 120), eofHitCounter.Image.Size);
667667
}
668+
669+
[Fact]
670+
public void Decode_Issue2666()
671+
{
672+
string path = Path.GetFullPath(Path.Combine(TestEnvironment.InputImagesDirectoryFullPath, TestImages.Png.Issue2666));
673+
using Image image = Image.Load(path);
674+
}
668675
}

tests/ImageSharp.Tests/TestImages.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ public static class Png
7373
public const string DisposeBackgroundRegion = "Png/animated/15-dispose-background-region.png";
7474
public const string DisposePreviousFirst = "Png/animated/12-dispose-prev-first.png";
7575
public const string BlendOverMultiple = "Png/animated/21-blend-over-multiple.png";
76+
public const string Issue2666 = "Png/issues/Issue_2666.png";
7677

7778
// Filtered test images from http://www.schaik.com/pngsuite/pngsuite_fil_png.html
7879
public const string Filter0 = "Png/filter0.png";
Lines changed: 3 additions & 0 deletions
Loading

0 commit comments

Comments
 (0)