Skip to content

Commit 130a806

Browse files
committed
Skip filling rectangles when effective fill area is zero width or height
1 parent 425bdbd commit 130a806

2 files changed

Lines changed: 56 additions & 1 deletion

File tree

src/ImageSharp.Drawing/Processing/Processors/Drawing/FillProcessor{TPixel}.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,15 @@ public FillProcessor(Configuration configuration, FillProcessor definition, Imag
2929
/// <inheritdoc/>
3030
protected override void OnFrameApply(ImageFrame<TPixel> source)
3131
{
32+
var interest = Rectangle.Intersect(this.SourceRectangle, source.Bounds());
33+
if (interest.Width == 0 || interest.Height == 0)
34+
{
35+
return;
36+
}
37+
3238
Configuration configuration = this.Configuration;
3339
IBrush brush = this.definition.Brush;
3440
GraphicsOptions options = this.definition.Options;
35-
var interest = Rectangle.Intersect(this.SourceRectangle, source.Bounds());
3641

3742
// If there's no reason for blending, then avoid it.
3843
if (this.IsSolidBrushWithoutBlending(out SolidBrush solidBrush))
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Runtime.InteropServices;
4+
using System.Text;
5+
using SixLabors.ImageSharp.Drawing.Processing;
6+
using SixLabors.ImageSharp.PixelFormats;
7+
using SixLabors.ImageSharp.Processing;
8+
using Xunit;
9+
10+
namespace SixLabors.ImageSharp.Drawing.Tests.Issues
11+
{
12+
public class Issue_65
13+
{
14+
[Theory]
15+
[InlineData(-100)] //Crash
16+
[InlineData(-99)] //Fine
17+
[InlineData(99)] //Fine
18+
[InlineData(100)] //Crash
19+
public void DrawRectactangleOutsideBoundsDrawingArea(int xpos)
20+
{
21+
int width = 100;
22+
int height = 100;
23+
24+
using (var image = new Image<Rgba32>(width, height, Color.Red))
25+
{
26+
var rectangle = new Rectangle(xpos, 0, width, height);
27+
28+
image.Mutate(x => x.Fill(Color.Black, rectangle));
29+
}
30+
}
31+
32+
[Theory]
33+
[InlineData(-110)] //Crash
34+
[InlineData(-99)] //Fine
35+
[InlineData(99)] //Fine
36+
[InlineData(110)] //Crash
37+
public void DrawCircleOutsideBoundsDrawingArea(int xpos)
38+
{
39+
int width = 100;
40+
int height = 100;
41+
42+
using (var image = new Image<Rgba32>(width, height, Color.Red))
43+
{
44+
var circle = new EllipsePolygon(xpos, 0, width, height);
45+
46+
image.Mutate(x => x.Fill(Color.Black, circle));
47+
}
48+
}
49+
}
50+
}

0 commit comments

Comments
 (0)