diff options
author | Hal Canary <halcanary@google.com> | 2017-02-27 16:42:03 -0500 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2017-03-01 15:16:06 +0000 |
commit | 62176db984b5623427401f8013ca1ae08e53c4f8 (patch) | |
tree | af43d3abe22ca1ca3a09a280014b0fe07275d7e3 /fuzz/fuzz.cpp | |
parent | dc54788f412412aa1437ed5b42a2baa80eab399d (diff) |
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 <kjlubick@google.com>
Reviewed-by: Herb Derby <herb@google.com>
Commit-Queue: Hal Canary <halcanary@google.com>
Diffstat (limited to 'fuzz/fuzz.cpp')
-rw-r--r-- | fuzz/fuzz.cpp | 38 |
1 files changed, 31 insertions, 7 deletions
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 <iostream> #include <signal.h> #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 <type> -b <path/to/file> [-n api-to-fuzz]\n"); @@ -53,6 +61,7 @@ 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_dump_canvas(sk_sp<SkData>); static void fuzz_raster_n32_canvas(sk_sp<SkData>); static void fuzz_skp(sk_sp<SkData>); #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<SkData> bytes) { FuzzCanvas(&fuzz, doc->beginPage(612.0f, 792.0f)); } +static void fuzz_dump_canvas(sk_sp<SkData> bytes) { + Fuzz fuzz(std::move(bytes)); + SkDebugCanvas debugCanvas(612, 792); + FuzzCanvas(&fuzz, &debugCanvas); + std::unique_ptr<SkCanvas> 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<SkData> bytes) { SkMemoryStream stream(bytes); SkDebugf("Decoding\n"); |