/src/karchive/autotests/ossfuzz/karchive_fuzzer_common.h
Line | Count | Source |
1 | | /* |
2 | | # SPDX-FileCopyrightText: 2025 Google LLC |
3 | | # SPDX-License-Identifier: Apache-2.0 |
4 | | # |
5 | | # Copyright 2025 Google LLC |
6 | | # |
7 | | # Licensed under the Apache License, Version 2.0 (the "License"); |
8 | | # you may not use this file except in compliance with the License. |
9 | | # You may obtain a copy of the License at |
10 | | # |
11 | | # http://www.apache.org/licenses/LICENSE-2.0 |
12 | | # |
13 | | # Unless required by applicable law or agreed to in writing, software |
14 | | # distributed under the License is distributed on an "AS IS" BASIS, |
15 | | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
16 | | # See the License for the specific language governing permissions and |
17 | | # limitations under the License. |
18 | | # |
19 | | ################################################################################ |
20 | | */ |
21 | | |
22 | | #include <karchive.h> |
23 | | |
24 | | inline void traverseArchive(const KArchiveDirectory *dir, const QString &path = QString()) |
25 | 1.15M | { |
26 | 1.34M | for (const auto &entryName : dir->entries()) { |
27 | 1.34M | auto entry = dir->entry(entryName); |
28 | | |
29 | 1.34M | if (entry->isFile()) { |
30 | 211k | auto file = static_cast<const KArchiveFile *>(entry); |
31 | 211k | QIODevice *device = file->createDevice(); |
32 | 211k | if (device) { |
33 | 210k | static const qint64 chunkSize = 1024 * 1024 * 100; |
34 | 210k | qint64 remainingSize = device->size(); |
35 | 210k | QByteArray array; |
36 | 210k | array.resize(int(qMin(chunkSize, remainingSize))); |
37 | 219k | while (remainingSize > 0) { |
38 | 17.9k | const qint64 currentChunkSize = qMin(chunkSize, remainingSize); |
39 | 17.9k | const qint64 n = device->read(array.data(), currentChunkSize); |
40 | 17.9k | if (n != currentChunkSize) { |
41 | 8.73k | delete device; |
42 | 8.73k | return; |
43 | 8.73k | } |
44 | 9.23k | remainingSize -= currentChunkSize; |
45 | 9.23k | } |
46 | 201k | delete device; |
47 | 201k | } |
48 | 1.13M | } else if (entry->isDirectory()) { |
49 | 1.13M | auto subDir = static_cast<const KArchiveDirectory *>(entry); |
50 | 1.13M | traverseArchive(subDir, path + QString::fromUtf8("/") + entryName); |
51 | 1.13M | } |
52 | 1.34M | } |
53 | 1.15M | } |