Coverage Report

Created: 2021-08-22 09:07

/src/skia/fuzz/oss_fuzz/FuzzSKSL2SPIRV.cpp
Line
Count
Source
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
8
#include "src/gpu/GrShaderCaps.h"
9
#include "src/sksl/SkSLCompiler.h"
10
11
#include "fuzz/Fuzz.h"
12
13
9.66k
bool FuzzSKSL2SPIRV(sk_sp<SkData> bytes) {
14
9.66k
    sk_sp<GrShaderCaps> caps = SkSL::ShaderCapsFactory::Default();
15
9.66k
    SkSL::Compiler compiler(caps.get());
16
9.66k
    SkSL::String output;
17
9.66k
    SkSL::Program::Settings settings;
18
19
    // This tells the compiler where the rt-flip uniform will live should it be required. For
20
    // fuzzing purposes we don't care where that is, but the compiler will report an error if we
21
    // leave them at their default invalid values, or if the offset overlaps another uniform.
22
9.66k
    settings.fRTFlipOffset  = 16384;
23
9.66k
    settings.fRTFlipSet     = 0;
24
9.66k
    settings.fRTFlipBinding = 0;
25
26
9.66k
    std::unique_ptr<SkSL::Program> program = compiler.convertProgram(
27
9.66k
                                                    SkSL::ProgramKind::kFragment,
28
9.66k
                                                    SkSL::String((const char*) bytes->data(),
29
9.66k
                                                                 bytes->size()),
30
9.66k
                                                    settings);
31
9.66k
    if (!program || !compiler.toSPIRV(*program, &output)) {
32
7.78k
        return false;
33
7.78k
    }
34
1.88k
    return true;
35
1.88k
}
36
37
#if defined(SK_BUILD_FOR_LIBFUZZER)
38
183k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
39
183k
    if (size > 3000) {
40
151
        return 0;
41
151
    }
42
183k
    auto bytes = SkData::MakeWithoutCopy(data, size);
43
183k
    FuzzSKSL2SPIRV(bytes);
44
183k
    return 0;
45
183k
}
46
#endif