From 1991f5502edef073a005d6efbbc710d8c72f1a8a Mon Sep 17 00:00:00 2001 From: Kevin Lubick Date: Tue, 27 Feb 2018 10:59:10 -0500 Subject: Tweak API fuzzers to run better in libfuzzer Prevents logging from cluttering the stats. Better handles limited memory. Bug: skia: Change-Id: I12c1a46875fd9120938cab520ef70de69c451ad8 Reviewed-on: https://skia-review.googlesource.com/110642 Reviewed-by: Mike Klein Commit-Queue: Kevin Lubick --- fuzz/FuzzCanvas.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) (limited to 'fuzz/FuzzCanvas.cpp') 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 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(fuzz)) { fuzz->next(¢er); } 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(¢er.fLeft, 0, img.width() - 1); fuzz->nextRange(¢er.fTop, 0, img.height() - 1); fuzz->nextRange(¢er.fRight, center.fLeft + 1, img.width()); -- cgit v1.2.3