diff --git a/src/core/SkCanvas.cpp b/src/core/SkCanvas.cpp index 49da8eb3a7..9f13a711c2 100644 --- a/src/core/SkCanvas.cpp +++ b/src/core/SkCanvas.cpp @@ -1768,11 +1768,18 @@ void SkCanvas::drawImage(const SkImage* image, SkScalar x, SkScalar y, const SkP this->onDrawImage(image, x, y, paint); } +// Returns true if the rect can be "filled" : non-empty and finite +static bool fillable(const SkRect& r) { + SkScalar w = r.width(); + SkScalar h = r.height(); + return SkScalarIsFinite(w) && w > 0 && SkScalarIsFinite(h) && h > 0; +} + void SkCanvas::drawImageRect(const SkImage* image, const SkRect& src, const SkRect& dst, const SkPaint* paint, SrcRectConstraint constraint) { TRACE_EVENT0("skia", TRACE_FUNC); RETURN_ON_NULL(image); - if (dst.isEmpty() || src.isEmpty()) { + if (!fillable(dst) || !fillable(src)) { return; } this->onDrawImageRect(image, &src, dst, paint, constraint); diff --git a/tests/ImageTest.cpp b/tests/ImageTest.cpp index 6cc0fee4d9..83b1c7983d 100644 --- a/tests/ImageTest.cpp +++ b/tests/ImageTest.cpp @@ -29,6 +29,7 @@ #include "Test.h" #include "Resources.h" +#include "sk_pixel_iter.h" #include "sk_tool_utils.h" #if SK_SUPPORT_GPU @@ -1392,3 +1393,32 @@ DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ImageScalePixels_Gpu, reporter, ctxInfo) { test_scale_pixels(reporter, gpuImage.get(), pmRed); } #endif + +static sk_sp any_image_will_do() { + return GetResourceAsImage("images/mandrill_32.png"); +} + +DEF_TEST(Image_nonfinite_dst, reporter) { + auto surf = SkSurface::MakeRasterN32Premul(10, 10); + auto img = any_image_will_do(); + SkPaint paint; + + for (SkScalar bad : { SK_ScalarInfinity, SK_ScalarNaN}) { + for (int bits = 1; bits <= 15; ++bits) { + SkRect dst = { 0, 0, 10, 10 }; + if (bits & 1) dst.fLeft = bad; + if (bits & 2) dst.fTop = bad; + if (bits & 4) dst.fRight = bad; + if (bits & 8) dst.fBottom = bad; + + surf->getCanvas()->drawImageRect(img, dst, &paint); + + // we should draw nothing + sk_tool_utils::PixelIter iter(surf.get()); + while (void* addr = iter.next()) { + REPORTER_ASSERT(reporter, *(SkPMColor*)addr == 0); + } + } + } +} +