don't draw images with nonfinite dst bounds

Bug: skia:
Change-Id: I95f32f8b9d6c47c3d95c0a19f7fdaaa6a648ef09
Reviewed-on: https://skia-review.googlesource.com/101745
Reviewed-by: Cary Clark <caryclark@google.com>
Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
Mike Reed 2018-01-30 11:15:27 -05:00 committed by Skia Commit-Bot
parent 31ac39c77c
commit c4e31092b1
2 changed files with 38 additions and 1 deletions

View File

@ -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);

View File

@ -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<SkImage> 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);
}
}
}
}