diff options
author | Kevin Lubick <kjlubick@google.com> | 2019-03-11 11:09:40 -0400 |
---|---|---|
committer | Skia Commit-Bot <skia-commit-bot@chromium.org> | 2019-03-11 15:54:01 +0000 |
commit | e9c1ce89c005f2112ecb3b7120116706af1f2222 (patch) | |
tree | fe71470eb600a5f41e55d51bdf5f8137b636b70e /fuzz | |
parent | ca9e2a4288b28b9e80ef3a7b0456afe6e42a8378 (diff) | |
download | skia-e9c1ce89c005f2112ecb3b7120116706af1f2222.tar.gz |
Add oss-fuzz compatible fuzzers for sksl2*
Bug: skia:
Change-Id: I468517481fcae42155c4363d817405455181d3c3
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/199721
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Commit-Queue: Kevin Lubick <kjlubick@google.com>
Diffstat (limited to 'fuzz')
-rw-r--r-- | fuzz/FuzzMain.cpp | 74 | ||||
-rw-r--r-- | fuzz/oss_fuzz/FuzzSKSL2GLSL.cpp | 35 | ||||
-rw-r--r-- | fuzz/oss_fuzz/FuzzSKSL2Metal.cpp | 35 | ||||
-rw-r--r-- | fuzz/oss_fuzz/FuzzSKSL2SPIRV.cpp | 35 |
4 files changed, 151 insertions, 28 deletions
diff --git a/fuzz/FuzzMain.cpp b/fuzz/FuzzMain.cpp index 0ba3fc96a2..9b4e0214ed 100644 --- a/fuzz/FuzzMain.cpp +++ b/fuzz/FuzzMain.cpp @@ -23,10 +23,6 @@ #include "SkSurface.h" #include "SkTextBlob.h" -#if SK_SUPPORT_GPU -#include "SkSLCompiler.h" -#endif - #include "sk_tool_utils.h" #include <iostream> @@ -60,6 +56,8 @@ static constexpr char g_type_message[] = "How to interpret --bytes, one of:\n" "region_set_path\n" "skp\n" "sksl2glsl\n" + "sksl2metal\n" + "sksl2spirv\n" #if defined(SK_ENABLE_SKOTTIE) "skottie_json\n" #endif @@ -84,14 +82,13 @@ static void fuzz_path_deserialize(sk_sp<SkData>); static void fuzz_region_deserialize(sk_sp<SkData>); static void fuzz_region_set_path(sk_sp<SkData>); static void fuzz_skp(sk_sp<SkData>); +static void fuzz_sksl2glsl(sk_sp<SkData>); +static void fuzz_sksl2metal(sk_sp<SkData>); +static void fuzz_sksl2spirv(sk_sp<SkData>); static void fuzz_textblob_deserialize(sk_sp<SkData>); static void print_api_names(); -#if SK_SUPPORT_GPU -static void fuzz_sksl2glsl(sk_sp<SkData>); -#endif - #if defined(SK_ENABLE_SKOTTIE) static void fuzz_skottie_json(sk_sp<SkData>); #endif @@ -207,16 +204,22 @@ static int fuzz_file(SkString path, SkString type) { fuzz_skp(bytes); return 0; } - if (type.equals("textblob")) { - fuzz_textblob_deserialize(bytes); - return 0; - } -#if SK_SUPPORT_GPU if (type.equals("sksl2glsl")) { fuzz_sksl2glsl(bytes); return 0; } -#endif + if (type.equals("sksl2metal")) { + fuzz_sksl2metal(bytes); + return 0; + } + if (type.equals("sksl2spirv")) { + fuzz_sksl2spirv(bytes); + return 0; + } + if (type.equals("textblob")) { + fuzz_textblob_deserialize(bytes); + return 0; + } SkDebugf("Unknown type %s\n", type.c_str()); SkCommandLineFlags::PrintUsage(); return 1; @@ -250,6 +253,9 @@ static std::map<std::string, std::string> cf_map = { {"region_deserialize", "region_deserialize"}, {"region_set_path", "region_set_path"}, {"skjson", "json"}, + {"sksl2glsl", "sksl2glsl"}, + {"sksl2metal", "sksl2metal"}, + {"sksl2spirv", "sksl2spirv"}, #if defined(SK_ENABLE_SKOTTIE) {"skottie_json", "skottie_json"}, #endif @@ -706,20 +712,32 @@ static void fuzz_filter_fuzz(sk_sp<SkData> bytes) { SkDebugf("[terminated] filter_fuzz didn't crash!\n"); } -#if SK_SUPPORT_GPU +bool FuzzSKSL2GLSL(sk_sp<SkData> bytes); + static void fuzz_sksl2glsl(sk_sp<SkData> bytes) { - SkSL::Compiler compiler; - SkSL::String output; - SkSL::Program::Settings settings; - sk_sp<GrShaderCaps> caps = SkSL::ShaderCapsFactory::Default(); - settings.fCaps = caps.get(); - std::unique_ptr<SkSL::Program> program = compiler.convertProgram(SkSL::Program::kFragment_Kind, - SkSL::String((const char*) bytes->data()), - settings); - if (!program || !compiler.toGLSL(*program, &output)) { - SkDebugf("[terminated] Couldn't compile input.\n"); - return; + if (FuzzSKSL2GLSL(bytes)) { + SkDebugf("[terminated] Success! Compiled input to GLSL.\n"); + } else { + SkDebugf("[terminated] Could not compile input to GLSL.\n"); + } +} + +bool FuzzSKSL2SPIRV(sk_sp<SkData> bytes); + +static void fuzz_sksl2spirv(sk_sp<SkData> bytes) { + if (FuzzSKSL2SPIRV(bytes)) { + SkDebugf("[terminated] Success! Compiled input to SPIRV.\n"); + } else { + SkDebugf("[terminated] Could not compile input to SPIRV.\n"); + } +} + +bool FuzzSKSL2Metal(sk_sp<SkData> bytes); + +static void fuzz_sksl2metal(sk_sp<SkData> bytes) { + if (FuzzSKSL2Metal(bytes)) { + SkDebugf("[terminated] Success! Compiled input to SPIRV.\n"); + } else { + SkDebugf("[terminated] Could not compile input to SPIRV.\n"); } - SkDebugf("[terminated] Success! Compiled input.\n"); } -#endif diff --git a/fuzz/oss_fuzz/FuzzSKSL2GLSL.cpp b/fuzz/oss_fuzz/FuzzSKSL2GLSL.cpp new file mode 100644 index 0000000000..ba4a0a023b --- /dev/null +++ b/fuzz/oss_fuzz/FuzzSKSL2GLSL.cpp @@ -0,0 +1,35 @@ +/* + * Copyright 2019 Google, LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "GrShaderCaps.h" +#include "SkSLCompiler.h" + +#include "../Fuzz.h" + +bool FuzzSKSL2GLSL(sk_sp<SkData> bytes) { + SkSL::Compiler compiler; + SkSL::String output; + SkSL::Program::Settings settings; + sk_sp<GrShaderCaps> caps = SkSL::ShaderCapsFactory::Default(); + settings.fCaps = caps.get(); + std::unique_ptr<SkSL::Program> program = compiler.convertProgram( + SkSL::Program::kFragment_Kind, + SkSL::String((const char*) bytes->data()), + settings); + if (!program || !compiler.toGLSL(*program, &output)) { + return false; + } + return true; +} + +#if defined(IS_FUZZING_WITH_LIBFUZZER) +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + auto bytes = SkData::MakeWithoutCopy(data, size); + FuzzSKSL2GLSL(bytes); + return 0; +} +#endif diff --git a/fuzz/oss_fuzz/FuzzSKSL2Metal.cpp b/fuzz/oss_fuzz/FuzzSKSL2Metal.cpp new file mode 100644 index 0000000000..327bdbf2a2 --- /dev/null +++ b/fuzz/oss_fuzz/FuzzSKSL2Metal.cpp @@ -0,0 +1,35 @@ +/* + * Copyright 2019 Google, LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "GrShaderCaps.h" +#include "SkSLCompiler.h" + +#include "../Fuzz.h" + +bool FuzzSKSL2Metal(sk_sp<SkData> bytes) { + SkSL::Compiler compiler; + SkSL::String output; + SkSL::Program::Settings settings; + sk_sp<GrShaderCaps> caps = SkSL::ShaderCapsFactory::Default(); + settings.fCaps = caps.get(); + std::unique_ptr<SkSL::Program> program = compiler.convertProgram( + SkSL::Program::kFragment_Kind, + SkSL::String((const char*) bytes->data()), + settings); + if (!program || !compiler.toMetal(*program, &output)) { + return false; + } + return true; +} + +#if defined(IS_FUZZING_WITH_LIBFUZZER) +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + auto bytes = SkData::MakeWithoutCopy(data, size); + FuzzSKSL2Metal(bytes); + return 0; +} +#endif diff --git a/fuzz/oss_fuzz/FuzzSKSL2SPIRV.cpp b/fuzz/oss_fuzz/FuzzSKSL2SPIRV.cpp new file mode 100644 index 0000000000..83ee9103c4 --- /dev/null +++ b/fuzz/oss_fuzz/FuzzSKSL2SPIRV.cpp @@ -0,0 +1,35 @@ +/* + * Copyright 2019 Google, LLC + * + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ + +#include "GrShaderCaps.h" +#include "SkSLCompiler.h" + +#include "../Fuzz.h" + +bool FuzzSKSL2SPIRV(sk_sp<SkData> bytes) { + SkSL::Compiler compiler; + SkSL::String output; + SkSL::Program::Settings settings; + sk_sp<GrShaderCaps> caps = SkSL::ShaderCapsFactory::Default(); + settings.fCaps = caps.get(); + std::unique_ptr<SkSL::Program> program = compiler.convertProgram( + SkSL::Program::kFragment_Kind, + SkSL::String((const char*) bytes->data()), + settings); + if (!program || !compiler.toSPIRV(*program, &output)) { + return false; + } + return true; +} + +#if defined(IS_FUZZING_WITH_LIBFUZZER) +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { + auto bytes = SkData::MakeWithoutCopy(data, size); + FuzzSKSL2SPIRV(bytes); + return 0; +} +#endif |