Coverage Report

Created: 2021-08-22 09:07

/src/skia/fuzz/oss_fuzz/FuzzRegionDeserialize.cpp
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2018 Google Inc.
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
9
#include "include/core/SkCanvas.h"
10
#include "include/core/SkPaint.h"
11
#include "include/core/SkSurface.h"
12
#include "src/core/SkRegionPriv.h"
13
14
1.25k
bool FuzzRegionDeserialize(sk_sp<SkData> bytes) {
15
1.25k
    SkRegion region;
16
1.25k
    if (!region.readFromMemory(bytes->data(), bytes->size())) {
17
854
        return false;
18
854
    }
19
404
    region.computeRegionComplexity();
20
404
    region.isComplex();
21
404
    SkRegion r2;
22
404
    if (region == r2) {
23
1
        region.contains(0,0);
24
403
    } else {
25
403
        region.contains(1,1);
26
403
    }
27
404
    auto s = SkSurface::MakeRasterN32Premul(128, 128);
28
404
    if (!s) {
29
        // May return nullptr in memory-constrained fuzzing environments
30
0
        return false;
31
0
    }
32
404
    s->getCanvas()->drawRegion(region, SkPaint());
33
404
    SkDEBUGCODE(SkRegionPriv::Validate(region));
34
404
    return true;
35
404
}
36
37
// TODO(kjlubick): remove IS_FUZZING... after https://crrev.com/c/2410304 lands
38
#if defined(SK_BUILD_FOR_LIBFUZZER) || defined(IS_FUZZING_WITH_LIBFUZZER)
39
183k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
40
183k
    if (size > 512) {
41
151
        return 0;
42
151
    }
43
183k
    auto bytes = SkData::MakeWithoutCopy(data, size);
44
183k
    FuzzRegionDeserialize(bytes);
45
183k
    return 0;
46
183k
}
47
#endif