blob: 9904519b104eeb258193e1babf4ce98708a01938 [file] [log] [blame]
Kevin Lubicke9c1ce82019-03-11 11:09:40 -04001/*
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 Kleinc0bd9f92019-04-23 12:05:21 -05008#include "src/gpu/GrShaderCaps.h"
9#include "src/sksl/SkSLCompiler.h"
Kevin Lubicke9c1ce82019-03-11 11:09:40 -040010
Mike Kleinc0bd9f92019-04-23 12:05:21 -050011#include "fuzz/Fuzz.h"
Kevin Lubicke9c1ce82019-03-11 11:09:40 -040012
13bool FuzzSKSL2GLSL(sk_sp<SkData> bytes) {
Brian Osmand7e76592020-11-02 12:26:22 -050014 sk_sp<GrShaderCaps> caps = SkSL::ShaderCapsFactory::Default();
15 SkSL::Compiler compiler(caps.get());
Kevin Lubicke9c1ce82019-03-11 11:09:40 -040016 SkSL::String output;
17 SkSL::Program::Settings settings;
Kevin Lubicke9c1ce82019-03-11 11:09:40 -040018 std::unique_ptr<SkSL::Program> program = compiler.convertProgram(
John Stilesdbd4e6f2021-02-16 13:29:15 -050019 SkSL::ProgramKind::kFragment,
Kevin Lubick39cbe462019-03-11 15:38:00 -040020 SkSL::String((const char*) bytes->data(),
21 bytes->size()),
Kevin Lubicke9c1ce82019-03-11 11:09:40 -040022 settings);
23 if (!program || !compiler.toGLSL(*program, &output)) {
24 return false;
25 }
26 return true;
27}
28
Kevin Lubick493f89e2020-09-14 08:37:35 -040029#if defined(SK_BUILD_FOR_LIBFUZZER)
Kevin Lubicke9c1ce82019-03-11 11:09:40 -040030extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
Zepeng Hu5b35f212020-06-14 19:03:34 +000031 if (size > 3000) {
32 return 0;
33 }
Kevin Lubicke9c1ce82019-03-11 11:09:40 -040034 auto bytes = SkData::MakeWithoutCopy(data, size);
35 FuzzSKSL2GLSL(bytes);
36 return 0;
37}
38#endif