Skip to content

Commit

Permalink
Merge pull request SixLabors#964 from 101100/fix-indexoutofrangeexcep…
Browse files Browse the repository at this point in the history
…tion-in-fillregionprocessor

Fix IndexOutOfRangeException in FillRegionProcessor
  • Loading branch information
tocsoft committed Aug 11, 2019
2 parents 1891d9c + 0e7172e commit 08644cf
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 1 deletion.
Expand Up @@ -105,7 +105,7 @@ protected override void OnFrameApply(ImageFrame<TPixel> source, Rectangle source

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

for (int point = 0; point < pointsFound; point += 2)
for (int point = 0; point < pointsFound && point < buffer.Length - 1; point += 2)
{
// points will be paired up
float scanStart = buffer[point] - minX;
Expand Down
45 changes: 45 additions & 0 deletions tests/ImageSharp.Tests/Drawing/FillRegionProcessorTests.cs
Expand Up @@ -12,6 +12,7 @@
using SixLabors.Primitives;
using Xunit;
using SixLabors.ImageSharp.Processing.Processors.Drawing;
using SixLabors.Shapes;

namespace SixLabors.ImageSharp.Tests.Drawing
{
Expand Down Expand Up @@ -68,6 +69,50 @@ public void DrawOffCanvas()
}
}

[Fact]
public void DoesNotThrowForIssue928()
{
var rectText = new RectangleF(0, 0, 2000, 2000);
using (Image<Rgba32> img = new Image<Rgba32>((int)rectText.Width, (int)rectText.Height))
{
img.Mutate(x => x.Fill(Rgba32.Transparent));

img.Mutate(ctx => {
ctx.DrawLines(
Rgba32.Red,
0.984252f,
new PointF(104.762581f, 1074.99365f),
new PointF(104.758667f, 1075.01721f),
new PointF(104.757675f, 1075.04114f),
new PointF(104.759628f, 1075.065f),
new PointF(104.764488f, 1075.08838f),
new PointF(104.772186f, 1075.111f),
new PointF(104.782608f, 1075.13245f),
new PointF(104.782608f, 1075.13245f)
);
}
);
}
}

[Fact]
public void DoesNotThrowFillingTriangle()
{
using(var image = new Image<Rgba32>(28, 28))
{
var path = new Polygon(
new LinearLineSegment(new PointF(17.11f, 13.99659f), new PointF(14.01433f, 27.06201f)),
new LinearLineSegment(new PointF(14.01433f, 27.06201f), new PointF(13.79267f, 14.00023f)),
new LinearLineSegment(new PointF(13.79267f, 14.00023f), new PointF(17.11f, 13.99659f))
);

image.Mutate(ctx =>
{
ctx.Fill(Rgba32.White, path);
});
}
}

// Mocking the region throws an error in netcore2.0
private class MockRegion1 : Region
{
Expand Down

0 comments on commit 08644cf

Please sign in to comment.