diff options
author | Hal Canary <halcanary@google.com> | 2017-02-14 13:35:14 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-02-27 19:03:12 +0000 |
commit | 24ac42b373d9202a89538a1873df9275870c7632 (patch) | |
tree | 7f76aced9c8fe96ed016fdd522fd4deb1f7635e8 /fuzz/fuzz.cpp | |
parent | af19769831f1c4c3b90c85aa9f8851cd8bbf86d5 (diff) |
Fuzz PDF, N32, and Null Canvases
run `fuzz --type pdf_canvas` or `fuzz --type null_canvas` or
`fuzz --type n32_canvas`
Change-Id: Id70179d5578ed1e67006aef7823bf75fc1d7a4a6
Reviewed-on: https://skia-review.googlesource.com/8418
Reviewed-by: Kevin Lubick <kjlubick@google.com>
Commit-Queue: Hal Canary <halcanary@google.com>
Diffstat (limited to 'fuzz/fuzz.cpp')
-rw-r--r-- | fuzz/fuzz.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/fuzz/fuzz.cpp b/fuzz/fuzz.cpp index eb0675aeb0..9c59a1b687 100644 --- a/fuzz/fuzz.cpp +++ b/fuzz/fuzz.cpp @@ -10,9 +10,11 @@ #include "SkCodec.h" #include "SkCommandLineFlags.h" #include "SkData.h" +#include "SkDocument.h" #include "SkImage.h" #include "SkImageEncoder.h" #include "SkMallocPixelRef.h" +#include "SkNullCanvas.h" #include "SkPath.h" #include "SkRegion.h" #include "SkSurface.h" @@ -28,6 +30,8 @@ #include "sk_tool_utils.h" +#include "FuzzCanvas.h" + DEFINE_string2(bytes, b, "", "A path to a file or a directory. If a file, the contents will be used as the fuzz bytes. If a directory, all files in the directory will be used as fuzz bytes for the fuzzer, one at a time."); DEFINE_string2(name, n, "", "If --type is 'api', fuzz the API with this name."); @@ -47,6 +51,9 @@ static void fuzz_icc(sk_sp<SkData>); static void fuzz_img(sk_sp<SkData>, uint8_t, uint8_t); static void fuzz_path_deserialize(sk_sp<SkData>); static void fuzz_region_deserialize(sk_sp<SkData>); +static void fuzz_pdf_canvas(sk_sp<SkData>); +static void fuzz_null_canvas(sk_sp<SkData>); +static void fuzz_raster_n32_canvas(sk_sp<SkData>); static void fuzz_skp(sk_sp<SkData>); #if SK_SUPPORT_GPU static void fuzz_sksl2glsl(sk_sp<SkData>); @@ -115,6 +122,18 @@ static int fuzz_file(const char* path) { fuzz_skp(bytes); return 0; } + if (0 == strcmp("pdf_canvas", FLAGS_type[0])) { + fuzz_pdf_canvas(bytes); + return 0; + } + if (0 == strcmp("n32_canvas", FLAGS_type[0])) { + fuzz_raster_n32_canvas(bytes); + return 0; + } + if (0 == strcmp("null_canvas", FLAGS_type[0])) { + fuzz_null_canvas(bytes); + return 0; + } #if SK_SUPPORT_GPU if (0 == strcmp("sksl2glsl", FLAGS_type[0])) { fuzz_sksl2glsl(bytes); @@ -436,6 +455,29 @@ static void fuzz_img(sk_sp<SkData> bytes, uint8_t scale, uint8_t mode) { dump_png(bitmap); } +static void fuzz_null_canvas(sk_sp<SkData> bytes) { + Fuzz fuzz(std::move(bytes)); + FuzzCanvas(&fuzz, SkMakeNullCanvas().get()); +} + +static void fuzz_raster_n32_canvas(sk_sp<SkData> bytes) { + Fuzz fuzz(std::move(bytes)); + auto surface = SkSurface::MakeRasterN32Premul(612, 792); + SkASSERT(surface && surface->getCanvas()); + FuzzCanvas(&fuzz, surface->getCanvas()); +} + +static void fuzz_pdf_canvas(sk_sp<SkData> bytes) { + Fuzz fuzz(std::move(bytes)); + struct final : public SkWStream { + bool write(const void*, size_t n) override { fN += n; return true; } + size_t bytesWritten() const override { return fN; } + size_t fN = 0; + } stream; + auto doc = SkDocument::MakePDF(&stream); + FuzzCanvas(&fuzz, doc->beginPage(612.0f, 792.0f)); +} + static void fuzz_skp(sk_sp<SkData> bytes) { SkMemoryStream stream(bytes); SkDebugf("Decoding\n"); |