From 62176db984b5623427401f8013ca1ae08e53c4f8 Mon Sep 17 00:00:00 2001 From: Hal Canary Date: Mon, 27 Feb 2017 16:42:03 -0500 Subject: fuzz: dump_canvas For example: `fuzz --type _dump_canvas -b fuzz_file` Note well: this command-line usage is subject to change. Change-Id: Ida7368a699bafe2395604d8428a2d50cb0eff6aa Reviewed-on: https://skia-review.googlesource.com/9025 Reviewed-by: Kevin Lubick Reviewed-by: Herb Derby Commit-Queue: Hal Canary --- fuzz/fuzz.cpp | 38 +++++++++++++++++++++++++++++++------- 1 file changed, 31 insertions(+), 7 deletions(-) (limited to 'fuzz') diff --git a/fuzz/fuzz.cpp b/fuzz/fuzz.cpp index 9c59a1b687..12f11e5eb6 100644 --- a/fuzz/fuzz.cpp +++ b/fuzz/fuzz.cpp @@ -10,33 +10,41 @@ #include "SkCodec.h" #include "SkCommandLineFlags.h" #include "SkData.h" +#include "SkDebugCanvas.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" #include "SkOSFile.h" #include "SkOSPath.h" +#include "SkPath.h" #include "SkPicture.h" +#include "SkRegion.h" +#include "SkStream.h" +#include "SkSurface.h" + #if SK_SUPPORT_GPU #include "SkSLCompiler.h" #endif -#include "SkStream.h" +#include #include #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(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."); -DEFINE_string2(type, t, "api", "How to interpret --bytes, either 'image_scale', 'image_mode', 'skp', 'icc', or 'api'."); -DEFINE_string2(dump, d, "", "If not empty, dump 'image*' or 'skp' types as a PNG with this name."); +DEFINE_string2(type, t, "api", "How to interpret --bytes, either 'image_scale'" + ", 'image_mode', 'skp', 'icc', or 'api'."); +DEFINE_string2(dump, d, "", "If not empty, dump 'image*' or 'skp' types as a " + "PNG with this name."); static int printUsage() { SkDebugf("Usage: fuzz -t -b [-n api-to-fuzz]\n"); @@ -53,6 +61,7 @@ static void fuzz_path_deserialize(sk_sp); static void fuzz_region_deserialize(sk_sp); static void fuzz_pdf_canvas(sk_sp); static void fuzz_null_canvas(sk_sp); +static void fuzz_dump_canvas(sk_sp); static void fuzz_raster_n32_canvas(sk_sp); static void fuzz_skp(sk_sp); #if SK_SUPPORT_GPU @@ -130,6 +139,11 @@ static int fuzz_file(const char* path) { fuzz_raster_n32_canvas(bytes); return 0; } + // not a "real" thing to fuzz, used to debug errors found while fuzzing. + if (0 == strcmp("_dump_canvas", FLAGS_type[0])) { + fuzz_dump_canvas(bytes); + return 0; + } if (0 == strcmp("null_canvas", FLAGS_type[0])) { fuzz_null_canvas(bytes); return 0; @@ -478,6 +492,16 @@ static void fuzz_pdf_canvas(sk_sp bytes) { FuzzCanvas(&fuzz, doc->beginPage(612.0f, 792.0f)); } +static void fuzz_dump_canvas(sk_sp bytes) { + Fuzz fuzz(std::move(bytes)); + SkDebugCanvas debugCanvas(612, 792); + FuzzCanvas(&fuzz, &debugCanvas); + std::unique_ptr nullCanvas = SkMakeNullCanvas(); + UrlDataManager dataManager(SkString("data")); + Json::Value json = debugCanvas.toJSON(dataManager, debugCanvas.getSize(), nullCanvas.get()); + Json::StyledStreamWriter(" ").write(std::cout, json); +} + static void fuzz_skp(sk_sp bytes) { SkMemoryStream stream(bytes); SkDebugf("Decoding\n"); -- cgit v1.2.3