Coverage Report

Created: 2024-05-20 07:14

/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/SkStream.h"
9
#include "include/core/SkSurface.h"
10
#include "modules/skshaper/utils/FactoryHelpers.h"
11
#include "modules/svg/include/SkSVGDOM.h"
12
#include "modules/svg/include/SkSVGNode.h"
13
#include "tools/fonts/TestFontMgr.h"
14
15
#if defined(SK_ENABLE_SVG)
16
17
41
void FuzzSVG(const uint8_t *data, size_t size) {
18
41
    uint8_t w = 100;
19
41
    uint8_t h = 200;
20
21
41
    SkMemoryStream stream(data, size);
22
41
    sk_sp<SkSVGDOM> dom = SkSVGDOM::Builder()
23
41
                                  .setFontManager(ToolUtils::MakePortableFontMgr())
24
41
                                  .setTextShapingFactory(SkShapers::BestAvailable())
25
41
                                  .make(stream);
26
41
    if (!dom) {
27
12
        return;
28
12
    }
29
30
29
    auto s = SkSurfaces::Raster(SkImageInfo::MakeN32Premul(128, 128));
31
29
    if (!s) {
32
0
        return;
33
0
    }
34
29
    SkSize winSize = SkSize::Make(w, h);
35
29
    dom->setContainerSize(winSize);
36
29
    dom->containerSize();
37
29
    dom->render(s->getCanvas());
38
29
}
39
40
#if defined(SK_BUILD_FOR_LIBFUZZER)
41
190k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
42
190k
    if (size > 30000) {
43
220
        return 0;
44
220
    }
45
190k
    FuzzSVG(data, size);
46
190k
    return 0;
47
190k
}
48
#endif
49
50
#endif // SK_ENABLE_SVG