aboutsummaryrefslogtreecommitdiffhomepage
path: root/fuzz/FuzzCanvas.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'fuzz/FuzzCanvas.cpp')
-rw-r--r--fuzz/FuzzCanvas.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/fuzz/FuzzCanvas.cpp b/fuzz/FuzzCanvas.cpp
index 9e117af66f..42e31b6a4e 100644
--- a/fuzz/FuzzCanvas.cpp
+++ b/fuzz/FuzzCanvas.cpp
@@ -901,7 +901,10 @@ static SkBitmap make_fuzz_bitmap(Fuzz* fuzz) {
int w, h;
fuzz->nextRange(&w, 1, 1024);
fuzz->nextRange(&h, 1, 1024);
- bitmap.allocN32Pixels(w, h);
+ if (!bitmap.tryAllocN32Pixels(w, h)) {
+ SkDEBUGF(("Could not allocate pixels %d x %d", w, h));
+ return bitmap;
+ }
for (int y = 0; y < h; ++y) {
for (int x = 0; x < w; ++x) {
SkColor c;
@@ -973,6 +976,11 @@ static SkTDArray<uint8_t> make_fuzz_text(Fuzz* fuzz, const SkPaint& paint) {
if (SkPaint::kGlyphID_TextEncoding == paint.getTextEncoding()) {
int glyphRange = paint.getTypeface() ? paint.getTypeface()->countGlyphs()
: SkTypeface::MakeDefault()->countGlyphs();
+ if (glyphRange == 0) {
+ // Some fuzzing environments have no fonts, so empty array is the best
+ // we can do.
+ return array;
+ }
int glyphCount;
fuzz->nextRange(&glyphCount, 1, kMaxGlyphCount);
SkGlyphID* glyphs = (SkGlyphID*)array.append(glyphCount * sizeof(SkGlyphID));
@@ -1464,6 +1472,10 @@ static void fuzz_canvas(Fuzz* fuzz, SkCanvas* canvas, int depth = 9) {
if (make_fuzz_t<bool>(fuzz)) {
fuzz->next(&center);
} else { // Make valid center, see SkLatticeIter::Valid().
+ if (img.width() == 0 || img.height() == 0) {
+ // bitmap may not have had its pixels initialized.
+ break;
+ }
fuzz->nextRange(&center.fLeft, 0, img.width() - 1);
fuzz->nextRange(&center.fTop, 0, img.height() - 1);
fuzz->nextRange(&center.fRight, center.fLeft + 1, img.width());