Coverage Report

Created: 2026-03-12 07:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/kdesdk-thumbnailers/build/autotests/ossfuzz/pothumbnail_fuzzer.cc
Line
Count
Source
1
/*
2
 * SPDX-FileCopyrightText: 2025 Azhar Momin <azhar.momin@kdemail.net>
3
 * SPDX-License-Identifier: LGPL-2.0-or-later
4
 */
5
6
#include <QByteArray>
7
#include <QGuiApplication>
8
#include <QMimeDatabase>
9
#include <QSize>
10
#include <QTemporaryFile>
11
#include <QUrl>
12
#include <QVariant>
13
14
#include "pocreator.h"
15
16
static void runThumbnailer(const QString &fileName, const QString &mimetype)
17
11.9k
{
18
11.9k
    QSize targetSize(128, 128);
19
11.9k
    qreal dpr = 1.0;
20
11.9k
    float sequenceIndex = 0.0f;
21
22
11.9k
    KIO::ThumbnailRequest request(QUrl::fromLocalFile(fileName), targetSize, mimetype, dpr, sequenceIndex);
23
24
11.9k
    PoCreator thumbnailer(nullptr, {});
25
11.9k
    thumbnailer.create(request);
26
11.9k
}
27
28
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
29
148k
{
30
148k
    int argc = 0;
31
148k
    QGuiApplication app(argc, nullptr);
32
33
148k
    QByteArray b(reinterpret_cast<const char *>(data), static_cast<int>(size));
34
35
148k
    QTemporaryFile f;
36
148k
    if (!f.open()) {
37
0
        return 0;
38
0
    }
39
148k
    f.write(b);
40
148k
    f.close();
41
42
148k
    QMimeDatabase mimeDb;
43
148k
    QMimeType mimetype = mimeDb.mimeTypeForData(b);
44
45
148k
    runThumbnailer(f.fileName(), mimetype.name());
46
269k
    for (const QString &ancestor : mimetype.allAncestors()) {
47
269k
        if (ancestor != QLatin1String("application/octet-stream")) {
48
133k
            runThumbnailer(f.fileName(), ancestor);
49
133k
        }
50
269k
    }
51
52
148k
    return 0;
53
148k
}