Skip to content

Commit b238317

Browse files
authored
Merge pull request #964 from 101100/fix-indexoutofrangeexception-in-fillregionprocessor
Fix IndexOutOfRangeException in FillRegionProcessor
2 parents fb033fe + bff44f9 commit b238317

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ protected override void OnFrameApply(ImageFrame<TPixel> source, Rectangle source
105105

106106
QuickSort.Sort(buffer.Slice(0, pointsFound));
107107

108-
for (int point = 0; point < pointsFound; point += 2)
108+
for (int point = 0; point < pointsFound && point < buffer.Length - 1; point += 2)
109109
{
110110
// points will be paired up
111111
float scanStart = buffer[point] - minX;

tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using SixLabors.Primitives;
1313
using Xunit;
1414
using SixLabors.ImageSharp.Processing.Processors.Drawing;
15+
using SixLabors.Shapes;
1516

1617
namespace SixLabors.ImageSharp.Tests.Drawing
1718
{
@@ -68,6 +69,50 @@ public void DrawOffCanvas()
6869
}
6970
}
7071

72+
[Fact]
73+
public void DoesNotThrowForIssue928()
74+
{
75+
var rectText = new RectangleF(0, 0, 2000, 2000);
76+
using (Image<Rgba32> img = new Image<Rgba32>((int)rectText.Width, (int)rectText.Height))
77+
{
78+
img.Mutate(x => x.Fill(Rgba32.Transparent));
79+
80+
img.Mutate(ctx => {
81+
ctx.DrawLines(
82+
Rgba32.Red,
83+
0.984252f,
84+
new PointF(104.762581f, 1074.99365f),
85+
new PointF(104.758667f, 1075.01721f),
86+
new PointF(104.757675f, 1075.04114f),
87+
new PointF(104.759628f, 1075.065f),
88+
new PointF(104.764488f, 1075.08838f),
89+
new PointF(104.772186f, 1075.111f),
90+
new PointF(104.782608f, 1075.13245f),
91+
new PointF(104.782608f, 1075.13245f)
92+
);
93+
}
94+
);
95+
}
96+
}
97+
98+
[Fact]
99+
public void DoesNotThrowFillingTriangle()
100+
{
101+
using(var image = new Image<Rgba32>(28, 28))
102+
{
103+
var path = new Polygon(
104+
new LinearLineSegment(new PointF(17.11f, 13.99659f), new PointF(14.01433f, 27.06201f)),
105+
new LinearLineSegment(new PointF(14.01433f, 27.06201f), new PointF(13.79267f, 14.00023f)),
106+
new LinearLineSegment(new PointF(13.79267f, 14.00023f), new PointF(17.11f, 13.99659f))
107+
);
108+
109+
image.Mutate(ctx =>
110+
{
111+
ctx.Fill(Rgba32.White, path);
112+
});
113+
}
114+
}
115+
71116
// Mocking the region throws an error in netcore2.0
72117
private class MockRegion1 : Region
73118
{

0 commit comments

Comments
 (0)