Coverage Report

Created: 2021-08-22 09:07

/src/skia/fuzz/oss_fuzz/FuzzSVG.cpp
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2020 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 "include/core/SkData.h"
9
#include "include/core/SkStream.h"
10
#include "include/core/SkSurface.h"
11
#include "modules/svg/include/SkSVGDOM.h"
12
13
17.7k
void FuzzSVG(sk_sp<SkData> bytes) {
14
17.7k
    uint8_t w = 100;
15
17.7k
    uint8_t h = 200;
16
17
17.7k
    SkMemoryStream stream(bytes);
18
17.7k
    sk_sp<SkSVGDOM> dom = SkSVGDOM::MakeFromStream(stream);
19
17.7k
    if (!dom) {
20
7.74k
        return;
21
7.74k
    }
22
23
10.0k
    auto s = SkSurface::MakeRasterN32Premul(128, 128);
24
10.0k
    if (!s) {
25
0
        return;
26
0
    }
27
10.0k
    SkSize winSize = SkSize::Make(w, h);
28
10.0k
    dom->setContainerSize(winSize);
29
10.0k
    dom->containerSize();
30
10.0k
    dom->render(s->getCanvas());
31
32
10.0k
}
33
34
#if defined(SK_BUILD_FOR_LIBFUZZER)
35
183k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
36
183k
    if (size > 30000) {
37
151
        return 0;
38
151
    }
39
183k
    auto bytes = SkData::MakeWithoutCopy(data, size);
40
183k
    FuzzSVG(bytes);
41
183k
    return 0;
42
183k
}
43
#endif