check for null-device pixels in onWritePixels, so we don't crash

https://code.google.com/p/chromium/issues/detail?id=352616

Review URL: https://codereview.chromium.org/196223013

git-svn-id: http://skia.googlecode.com/svn/trunk@13802 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
reed@google.com 2014-03-14 14:02:58 +00:00
parent 13874c1ad8
commit 0d30c51c6c
2 changed files with 21 additions and 0 deletions

View File

@ -8,6 +8,21 @@
#include "gm.h"
#include "SkCanvas.h"
static void test_nulldev(SkCanvas* canvas) {
SkBitmap bm;
bm.setConfig(SkBitmap::kARGB_8888_Config, 30, 30);
// notice: no pixels mom! be sure we don't crash
// https://code.google.com/p/chromium/issues/detail?id=352616
SkCanvas c(bm);
SkBitmap src;
src.allocN32Pixels(10, 10);
src.eraseColor(SK_ColorRED);
// ensure we don't crash
c.writePixels(src, 0, 0);
}
static void draw_text_stroked(SkCanvas* canvas, const SkPaint& paint) {
SkPaint p(paint);
SkPoint loc = { 20, 450 };
@ -44,6 +59,7 @@ protected:
}
virtual void onDraw(SkCanvas* canvas) SK_OVERRIDE {
if (true) { test_nulldev(canvas); }
SkPaint paint;
paint.setAntiAlias(true);

View File

@ -352,6 +352,11 @@ static bool write_pixels(const SkImageInfo& dstInfo, void* dstPixels, size_t dst
bool SkBitmapDevice::onWritePixels(const SkImageInfo& srcInfo, const void* srcPixels,
size_t srcRowBytes, int x, int y) {
// since we don't stop creating un-pixeled devices yet, check for no pixels here
if (NULL == fBitmap.getPixels()) {
return false;
}
SkImageInfo dstInfo = fBitmap.info();
dstInfo.fWidth = srcInfo.width();
dstInfo.fHeight = srcInfo.height();