Coverage Report

Created: 2024-09-14 07:19

/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
61
void FuzzSVG(const uint8_t *data, size_t size) {
18
61
    uint8_t w = 100;
19
61
    uint8_t h = 200;
20
21
61
    SkMemoryStream stream(data, size);
22
61
    sk_sp<SkSVGDOM> dom = SkSVGDOM::Builder()
23
61
                                  .setFontManager(ToolUtils::MakePortableFontMgr())
24
61
                                  .setTextShapingFactory(SkShapers::BestAvailable())
25
61
                                  .make(stream);
26
61
    if (!dom) {
27
9
        return;
28
9
    }
29
30
52
    auto s = SkSurfaces::Raster(SkImageInfo::MakeN32Premul(128, 128));
31
52
    if (!s) {
32
0
        return;
33
0
    }
34
52
    SkSize winSize = SkSize::Make(w, h);
35
52
    dom->setContainerSize(winSize);
36
52
    dom->containerSize();
37
52
    dom->render(s->getCanvas());
38
52
}
39
40
#if defined(SK_BUILD_FOR_LIBFUZZER)
41
162k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
42
162k
    if (size > 30000) {
43
207
        return 0;
44
207
    }
45
162k
    FuzzSVG(data, size);
46
162k
    return 0;
47
162k
}
48
#endif
49
50
#endif // SK_ENABLE_SVG