Skip to content

Commit bd3afa0

Browse files
Limit access to target dimensions
1 parent 888d8b8 commit bd3afa0

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

ImageSharp.Drawing.sln

Lines changed: 1 addition & 1 deletion
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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,9 +136,17 @@ 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

149+
int width = this.Target.Width;
142150
for (int i = 0; i < scanline.Length; i++)
143151
{
144152
amounts[i] = scanline[i] * this.Options.BlendPercentage;

0 commit comments

Comments
 (0)