diff --git a/binding/Binding/SKBitmap.cs b/binding/Binding/SKBitmap.cs index 246d01ce..5883fa93 100644 --- a/binding/Binding/SKBitmap.cs +++ b/binding/Binding/SKBitmap.cs @@ -786,6 +786,9 @@ namespace SkiaSharp public SKBitmap Resize (SKImageInfo info, SKFilterQuality quality) { + if (info.IsEmpty) + return null; + var dst = new SKBitmap (info); if (ScalePixels (dst, quality)) { return dst; diff --git a/tests/Tests/SKBitmapTest.cs b/tests/Tests/SKBitmapTest.cs index b7f8ce99..9f671b4a 100644 --- a/tests/Tests/SKBitmapTest.cs +++ b/tests/Tests/SKBitmapTest.cs @@ -428,6 +428,26 @@ namespace SkiaSharp.Tests Assert.Equal(SKColors.Blue, dstBmp.GetPixel(75, 75)); } + [SkippableTheory] + [InlineData(-1, -1)] + [InlineData(0, 0)] + [InlineData(-1, 10)] + [InlineData(10, -1)] + [InlineData(0, 10)] + [InlineData(10, 0)] + public void BitmapDoesNotCrashOnInvalidResizes(int width, int hight) + { + using var bitmap = CreateTestBitmap(); + + var newInfo = bitmap.Info; + newInfo.Width = width; + newInfo.Height = hight; + + using var newBitmap = bitmap.Resize(newInfo, SKFilterQuality.High); + + Assert.Null(newBitmap); + } + [SkippableFact] public void CanScalePixels() {