Kevin Lubick | e9c1ce8 | 2019-03-11 11:09:40 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2019 Google, LLC |
| 3 | * |
| 4 | * Use of this source code is governed by a BSD-style license that can be |
| 5 | * found in the LICENSE file. |
| 6 | */ |
| 7 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 8 | #include "src/gpu/GrShaderCaps.h" |
| 9 | #include "src/sksl/SkSLCompiler.h" |
Kevin Lubick | e9c1ce8 | 2019-03-11 11:09:40 -0400 | [diff] [blame] | 10 | |
Mike Klein | c0bd9f9 | 2019-04-23 12:05:21 -0500 | [diff] [blame] | 11 | #include "fuzz/Fuzz.h" |
Kevin Lubick | e9c1ce8 | 2019-03-11 11:09:40 -0400 | [diff] [blame] | 12 | |
| 13 | bool FuzzSKSL2GLSL(sk_sp<SkData> bytes) { |
| 14 | SkSL::Compiler compiler; |
| 15 | SkSL::String output; |
| 16 | SkSL::Program::Settings settings; |
| 17 | sk_sp<GrShaderCaps> caps = SkSL::ShaderCapsFactory::Default(); |
| 18 | settings.fCaps = caps.get(); |
| 19 | std::unique_ptr<SkSL::Program> program = compiler.convertProgram( |
| 20 | SkSL::Program::kFragment_Kind, |
Kevin Lubick | 39cbe46 | 2019-03-11 15:38:00 -0400 | [diff] [blame] | 21 | SkSL::String((const char*) bytes->data(), |
| 22 | bytes->size()), |
Kevin Lubick | e9c1ce8 | 2019-03-11 11:09:40 -0400 | [diff] [blame] | 23 | settings); |
| 24 | if (!program || !compiler.toGLSL(*program, &output)) { |
| 25 | return false; |
| 26 | } |
| 27 | return true; |
| 28 | } |
| 29 | |
Kevin Lubick | 493f89e | 2020-09-14 08:37:35 -0400 | [diff] [blame] | 30 | #if defined(SK_BUILD_FOR_LIBFUZZER) |
Kevin Lubick | e9c1ce8 | 2019-03-11 11:09:40 -0400 | [diff] [blame] | 31 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
Zepeng Hu | 5b35f21 | 2020-06-14 19:03:34 +0000 | [diff] [blame] | 32 | if (size > 3000) { |
| 33 | return 0; |
| 34 | } |
Kevin Lubick | e9c1ce8 | 2019-03-11 11:09:40 -0400 | [diff] [blame] | 35 | auto bytes = SkData::MakeWithoutCopy(data, size); |
| 36 | FuzzSKSL2GLSL(bytes); |
| 37 | return 0; |
| 38 | } |
| 39 | #endif |