diff options
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"); |