Coverage Report

Created: 2021-08-22 09:07

/src/skia/fuzz/oss_fuzz/FuzzImage.cpp
Line
Count
Source (jump to first uncovered line)
1
/*
2
 * Copyright 2018 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/SkCanvas.h"
9
#include "include/core/SkData.h"
10
#include "include/core/SkImage.h"
11
#include "include/core/SkPaint.h"
12
#include "include/core/SkSurface.h"
13
14
7.20k
bool FuzzImageDecode(sk_sp<SkData> bytes) {
15
7.20k
    auto img = SkImage::MakeFromEncoded(bytes);
16
7.20k
    if (nullptr == img.get()) {
17
4.18k
        return false;
18
4.18k
    }
19
20
3.02k
    auto s = SkSurface::MakeRasterN32Premul(128, 128);
21
3.02k
    if (!s) {
22
        // May return nullptr in memory-constrained fuzzing environments
23
0
        return false;
24
0
    }
25
26
3.02k
    s->getCanvas()->drawImage(img, 0, 0);
27
3.02k
    return true;
28
3.02k
}
29
30
// TODO(kjlubick): remove IS_FUZZING... after https://crrev.com/c/2410304 lands
31
#if defined(SK_BUILD_FOR_LIBFUZZER) || defined(IS_FUZZING_WITH_LIBFUZZER)
32
183k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
33
183k
    if (size > 10240) {
34
151
        return 0;
35
151
    }
36
183k
    auto bytes = SkData::MakeWithoutCopy(data, size);
37
183k
    FuzzImageDecode(bytes);
38
183k
    return 0;
39
183k
}
40
#endif