Coverage Report

Created: 2024-09-14 07:19

/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
9.92k
bool FuzzImageDecode(const uint8_t *data, size_t size) {
15
9.92k
    auto img = SkImages::DeferredFromEncodedData(SkData::MakeWithoutCopy(data, size));
16
9.92k
    if (nullptr == img.get()) {
17
4.55k
        return false;
18
4.55k
    }
19
20
5.37k
    auto s = SkSurfaces::Raster(SkImageInfo::MakeN32Premul(128, 128));
21
5.37k
    if (!s) {
22
        // May return nullptr in memory-constrained fuzzing environments
23
0
        return false;
24
0
    }
25
26
5.37k
    s->getCanvas()->drawImage(img, 0, 0);
27
5.37k
    return true;
28
5.37k
}
29
30
#if defined(SK_BUILD_FOR_LIBFUZZER)
31
162k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
32
162k
    if (size > 10240) {
33
207
        return 0;
34
207
    }
35
162k
    FuzzImageDecode(data, size);
36
162k
    return 0;
37
162k
}
38
#endif