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>
This commit is contained in:
parent
ca9e2a4288
commit
e9c1ce89c0
4
BUILD.gn
4
BUILD.gn
@ -1965,6 +1965,7 @@ if (skia_enable_tools) {
|
|||||||
"tools",
|
"tools",
|
||||||
"tools/debugger",
|
"tools/debugger",
|
||||||
"tools/fonts",
|
"tools/fonts",
|
||||||
|
"src/sksl",
|
||||||
]
|
]
|
||||||
sources = [
|
sources = [
|
||||||
"fuzz/Fuzz.cpp",
|
"fuzz/Fuzz.cpp",
|
||||||
@ -1988,6 +1989,9 @@ if (skia_enable_tools) {
|
|||||||
"fuzz/oss_fuzz/FuzzPathDeserialize.cpp",
|
"fuzz/oss_fuzz/FuzzPathDeserialize.cpp",
|
||||||
"fuzz/oss_fuzz/FuzzRegionDeserialize.cpp",
|
"fuzz/oss_fuzz/FuzzRegionDeserialize.cpp",
|
||||||
"fuzz/oss_fuzz/FuzzRegionSetPath.cpp",
|
"fuzz/oss_fuzz/FuzzRegionSetPath.cpp",
|
||||||
|
"fuzz/oss_fuzz/FuzzSKSL2GLSL.cpp",
|
||||||
|
"fuzz/oss_fuzz/FuzzSKSL2Metal.cpp",
|
||||||
|
"fuzz/oss_fuzz/FuzzSKSL2SPIRV.cpp",
|
||||||
"fuzz/oss_fuzz/FuzzTextBlobDeserialize.cpp",
|
"fuzz/oss_fuzz/FuzzTextBlobDeserialize.cpp",
|
||||||
"tools/UrlDataManager.cpp",
|
"tools/UrlDataManager.cpp",
|
||||||
"tools/debugger/SkDebugCanvas.cpp",
|
"tools/debugger/SkDebugCanvas.cpp",
|
||||||
|
@ -23,10 +23,6 @@
|
|||||||
#include "SkSurface.h"
|
#include "SkSurface.h"
|
||||||
#include "SkTextBlob.h"
|
#include "SkTextBlob.h"
|
||||||
|
|
||||||
#if SK_SUPPORT_GPU
|
|
||||||
#include "SkSLCompiler.h"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include "sk_tool_utils.h"
|
#include "sk_tool_utils.h"
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -60,6 +56,8 @@ static constexpr char g_type_message[] = "How to interpret --bytes, one of:\n"
|
|||||||
"region_set_path\n"
|
"region_set_path\n"
|
||||||
"skp\n"
|
"skp\n"
|
||||||
"sksl2glsl\n"
|
"sksl2glsl\n"
|
||||||
|
"sksl2metal\n"
|
||||||
|
"sksl2spirv\n"
|
||||||
#if defined(SK_ENABLE_SKOTTIE)
|
#if defined(SK_ENABLE_SKOTTIE)
|
||||||
"skottie_json\n"
|
"skottie_json\n"
|
||||||
#endif
|
#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_deserialize(sk_sp<SkData>);
|
||||||
static void fuzz_region_set_path(sk_sp<SkData>);
|
static void fuzz_region_set_path(sk_sp<SkData>);
|
||||||
static void fuzz_skp(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 fuzz_textblob_deserialize(sk_sp<SkData>);
|
||||||
|
|
||||||
static void print_api_names();
|
static void print_api_names();
|
||||||
|
|
||||||
#if SK_SUPPORT_GPU
|
|
||||||
static void fuzz_sksl2glsl(sk_sp<SkData>);
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#if defined(SK_ENABLE_SKOTTIE)
|
#if defined(SK_ENABLE_SKOTTIE)
|
||||||
static void fuzz_skottie_json(sk_sp<SkData>);
|
static void fuzz_skottie_json(sk_sp<SkData>);
|
||||||
#endif
|
#endif
|
||||||
@ -207,16 +204,22 @@ static int fuzz_file(SkString path, SkString type) {
|
|||||||
fuzz_skp(bytes);
|
fuzz_skp(bytes);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (type.equals("textblob")) {
|
|
||||||
fuzz_textblob_deserialize(bytes);
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
#if SK_SUPPORT_GPU
|
|
||||||
if (type.equals("sksl2glsl")) {
|
if (type.equals("sksl2glsl")) {
|
||||||
fuzz_sksl2glsl(bytes);
|
fuzz_sksl2glsl(bytes);
|
||||||
return 0;
|
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());
|
SkDebugf("Unknown type %s\n", type.c_str());
|
||||||
SkCommandLineFlags::PrintUsage();
|
SkCommandLineFlags::PrintUsage();
|
||||||
return 1;
|
return 1;
|
||||||
@ -250,6 +253,9 @@ static std::map<std::string, std::string> cf_map = {
|
|||||||
{"region_deserialize", "region_deserialize"},
|
{"region_deserialize", "region_deserialize"},
|
||||||
{"region_set_path", "region_set_path"},
|
{"region_set_path", "region_set_path"},
|
||||||
{"skjson", "json"},
|
{"skjson", "json"},
|
||||||
|
{"sksl2glsl", "sksl2glsl"},
|
||||||
|
{"sksl2metal", "sksl2metal"},
|
||||||
|
{"sksl2spirv", "sksl2spirv"},
|
||||||
#if defined(SK_ENABLE_SKOTTIE)
|
#if defined(SK_ENABLE_SKOTTIE)
|
||||||
{"skottie_json", "skottie_json"},
|
{"skottie_json", "skottie_json"},
|
||||||
#endif
|
#endif
|
||||||
@ -706,20 +712,32 @@ static void fuzz_filter_fuzz(sk_sp<SkData> bytes) {
|
|||||||
SkDebugf("[terminated] filter_fuzz didn't crash!\n");
|
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) {
|
static void fuzz_sksl2glsl(sk_sp<SkData> bytes) {
|
||||||
SkSL::Compiler compiler;
|
if (FuzzSKSL2GLSL(bytes)) {
|
||||||
SkSL::String output;
|
SkDebugf("[terminated] Success! Compiled input to GLSL.\n");
|
||||||
SkSL::Program::Settings settings;
|
} else {
|
||||||
sk_sp<GrShaderCaps> caps = SkSL::ShaderCapsFactory::Default();
|
SkDebugf("[terminated] Could not compile input to GLSL.\n");
|
||||||
settings.fCaps = caps.get();
|
}
|
||||||
std::unique_ptr<SkSL::Program> program = compiler.convertProgram(SkSL::Program::kFragment_Kind,
|
}
|
||||||
SkSL::String((const char*) bytes->data()),
|
|
||||||
settings);
|
bool FuzzSKSL2SPIRV(sk_sp<SkData> bytes);
|
||||||
if (!program || !compiler.toGLSL(*program, &output)) {
|
|
||||||
SkDebugf("[terminated] Couldn't compile input.\n");
|
static void fuzz_sksl2spirv(sk_sp<SkData> bytes) {
|
||||||
return;
|
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
|
|
||||||
|
35
fuzz/oss_fuzz/FuzzSKSL2GLSL.cpp
Normal file
35
fuzz/oss_fuzz/FuzzSKSL2GLSL.cpp
Normal file
@ -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
|
35
fuzz/oss_fuzz/FuzzSKSL2Metal.cpp
Normal file
35
fuzz/oss_fuzz/FuzzSKSL2Metal.cpp
Normal file
@ -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
|
35
fuzz/oss_fuzz/FuzzSKSL2SPIRV.cpp
Normal file
35
fuzz/oss_fuzz/FuzzSKSL2SPIRV.cpp
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user