Skip to content

Commit a11c5e7

Browse files
Merge pull request #2673 from SixLabors/js/fix-2663
Make DrawImage processor more robust to bad input.
2 parents 72d603b + a940a55 commit a11c5e7

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

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

0 commit comments

Comments
 (0)