Skip to content

Commit d0c4e1d

Browse files
committed
Add regression test for GDI+ crash in FillRectangle
1 parent c91c408 commit d0c4e1d

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/System.Drawing.Common/tests/System/Drawing/GraphicsTests.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3002,5 +3002,19 @@ public void Graphics_FillRoundedRectangle_Float()
30023002
graphics.FillRoundedRectangle(Brushes.Green, new RectangleF(0, 0, 10, 10), new(2, 2));
30033003
VerifyBitmapNotEmpty(bitmap);
30043004
}
3005+
3006+
[Fact]
3007+
public void FillRectangle_AntiAlias_24bppRgb_OutOfBounds_ThrowsArgumentException()
3008+
{
3009+
using Bitmap bmp = new(256, 256, PixelFormat.Format24bppRgb);
3010+
using Graphics graphics = Graphics.FromImage(bmp);
3011+
graphics.SmoothingMode = SmoothingMode.AntiAlias;
3012+
3013+
// This combination causes a crash in GDI+ on .NET 9+ (ExecutionEngineException)
3014+
// and AccessViolationException on .NET 8.
3015+
// We expect our fix to throw ArgumentException instead.
3016+
Assert.Throws<ArgumentException>(() =>
3017+
graphics.FillRectangle(Brushes.Green, new RectangleF(190.5f, 180.5f, 100, 100)));
3018+
}
30053019
#endif
30063020
}

0 commit comments

Comments
 (0)