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) { |
Brian Osman | d7e7659 | 2020-11-02 12:26:22 -0500 | [diff] [blame] | 14 | sk_sp<GrShaderCaps> caps = SkSL::ShaderCapsFactory::Default(); |
| 15 | SkSL::Compiler compiler(caps.get()); |
Kevin Lubick | e9c1ce8 | 2019-03-11 11:09:40 -0400 | [diff] [blame] | 16 | SkSL::String output; |
| 17 | SkSL::Program::Settings settings; |
Kevin Lubick | e9c1ce8 | 2019-03-11 11:09:40 -0400 | [diff] [blame] | 18 | std::unique_ptr<SkSL::Program> program = compiler.convertProgram( |
John Stiles | dbd4e6f | 2021-02-16 13:29:15 -0500 | [diff] [blame] | 19 | SkSL::ProgramKind::kFragment, |
Kevin Lubick | 39cbe46 | 2019-03-11 15:38:00 -0400 | [diff] [blame] | 20 | SkSL::String((const char*) bytes->data(), |
| 21 | bytes->size()), |
Kevin Lubick | e9c1ce8 | 2019-03-11 11:09:40 -0400 | [diff] [blame] | 22 | settings); |
| 23 | if (!program || !compiler.toGLSL(*program, &output)) { |
| 24 | return false; |
| 25 | } |
| 26 | return true; |
| 27 | } |
| 28 | |
Kevin Lubick | 493f89e | 2020-09-14 08:37:35 -0400 | [diff] [blame] | 29 | #if defined(SK_BUILD_FOR_LIBFUZZER) |
Kevin Lubick | e9c1ce8 | 2019-03-11 11:09:40 -0400 | [diff] [blame] | 30 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
Zepeng Hu | 5b35f21 | 2020-06-14 19:03:34 +0000 | [diff] [blame] | 31 | if (size > 3000) { |
| 32 | return 0; |
| 33 | } |
Kevin Lubick | e9c1ce8 | 2019-03-11 11:09:40 -0400 | [diff] [blame] | 34 | auto bytes = SkData::MakeWithoutCopy(data, size); |
| 35 | FuzzSKSL2GLSL(bytes); |
| 36 | return 0; |
| 37 | } |
| 38 | #endif |