/src/kio-extras/build/thumbnail/autotests/ossfuzz/djvuthumbnail_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 | | #include <KConfigGroup> |
14 | | #include <KSharedConfig> |
15 | | |
16 | | #include "djvucreator.h" |
17 | | |
18 | | static void runThumbnailer(const QString &fileName, const QString &mimetype) |
19 | 920 | { |
20 | 920 | QSize targetSize(128, 128); |
21 | 920 | qreal dpr = 1.0; |
22 | 920 | float sequenceIndex = 0.0f; |
23 | | |
24 | 920 | KIO::ThumbnailRequest request(QUrl::fromLocalFile(fileName), targetSize, mimetype, dpr, sequenceIndex); |
25 | | |
26 | 920 | DjVuCreator thumbnailer(nullptr, {}); |
27 | 920 | thumbnailer.create(request); |
28 | 920 | } |
29 | | |
30 | | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) |
31 | 148k | { |
32 | 148k | int argc = 0; |
33 | 148k | QGuiApplication app(argc, nullptr); |
34 | | |
35 | 148k | KConfigGroup globalConfig(KSharedConfig::openConfig(), QStringLiteral("PreviewSettings")); |
36 | 148k | globalConfig.writeEntry("MaximumSize", 2llu * 1024 * 1024 * 1024); |
37 | | |
38 | 148k | QByteArray b(reinterpret_cast<const char *>(data), static_cast<int>(size)); |
39 | | |
40 | 148k | QTemporaryFile f; |
41 | 148k | if (!f.open()) { |
42 | 0 | return 0; |
43 | 0 | } |
44 | 148k | f.write(b); |
45 | 148k | f.close(); |
46 | | |
47 | 148k | QMimeDatabase mimeDb; |
48 | 148k | QMimeType mimetype = mimeDb.mimeTypeForData(b); |
49 | | |
50 | 148k | runThumbnailer(f.fileName(), mimetype.name()); |
51 | 269k | for (const QString &ancestor : mimetype.allAncestors()) { |
52 | 269k | if (ancestor != QLatin1String("application/octet-stream")) { |
53 | 133k | runThumbnailer(f.fileName(), ancestor); |
54 | 133k | } |
55 | 269k | } |
56 | | |
57 | 148k | return 0; |
58 | 148k | } |