aboutsummaryrefslogtreecommitdiffhomepage
path: root/fuzz/FuzzCanvas.cpp
diff options
context:
space:
mode:
authorGravatar Kevin Lubick <kjlubick@google.com>2018-02-27 10:59:10 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2018-02-27 16:21:49 +0000
commit1991f5502edef073a005d6efbbc710d8c72f1a8a (patch)
tree928a2405398ca865f6407e3c8e03414d65cb7679 /fuzz/FuzzCanvas.cpp
parentf895a420c93f18df10dc95da182025847a0e061a (diff)
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 <mtklein@chromium.org> Commit-Queue: Kevin Lubick <kjlubick@google.com>
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());