Skip to content

Commit 435aae4

Browse files
Merge pull request #350 from SixLabors/js/issue-348
RecolorBrush - Limit access to target dimensions
2 parents 888d8b8 + 51173a8 commit 435aae4

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed

ImageSharp.Drawing.sln

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ EndProject
2828
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ISSUE_TEMPLATE", "ISSUE_TEMPLATE", "{FBE8C1AD-5AEC-4514-9B64-091D8E145865}"
2929
ProjectSection(SolutionItems) = preProject
3030
.github\ISSUE_TEMPLATE\config.yml = .github\ISSUE_TEMPLATE\config.yml
31-
.github\ISSUE_TEMPLATE\oss-bug-report.md = .github\ISSUE_TEMPLATE\oss-bug-report.md
31+
.github\ISSUE_TEMPLATE\oss-bug-report.yml = .github\ISSUE_TEMPLATE\oss-bug-report.yml
3232
EndProjectSection
3333
EndProject
3434
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{815C0625-CD3D-440F-9F80-2D83856AB7AE}"

src/ImageSharp.Drawing/Processing/RecolorBrush.cs

+9-2
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,15 @@ public RecolorBrushApplicator(
136136
/// <inheritdoc />
137137
public override void Apply(Span<float> scanline, int x, int y)
138138
{
139-
Span<float> amounts = this.blenderBuffers.AmountSpan.Slice(0, scanline.Length);
140-
Span<TPixel> overlays = this.blenderBuffers.OverlaySpan.Slice(0, scanline.Length);
139+
if (x < 0 || y < 0 || x >= this.Target.Width || y >= this.Target.Height)
140+
{
141+
return;
142+
}
143+
144+
// Limit the scanline to the bounds of the image relative to x.
145+
scanline = scanline[..Math.Min(this.Target.Width - x, scanline.Length)];
146+
Span<float> amounts = this.blenderBuffers.AmountSpan[..scanline.Length];
147+
Span<TPixel> overlays = this.blenderBuffers.OverlaySpan[..scanline.Length];
141148

142149
for (int i = 0; i < scanline.Length; i++)
143150
{

0 commit comments

Comments
 (0)