Coverage Report

Created: 2024-05-20 07:14

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