/src/kcompressiondevice_fuzzer.cc
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 | | /* |
23 | | Usage: |
24 | | python infra/helper.py build_image karchive |
25 | | python infra/helper.py build_fuzzers --sanitizer undefined|address|memory karchive |
26 | | python infra/helper.py run_fuzzer karchive ktar_[gz|bz2|xz|zst|lz]_fuzzer |
27 | | */ |
28 | | |
29 | | #include <QBuffer> |
30 | | #include <QCoreApplication> |
31 | | |
32 | | #include <kcompressiondevice.h> |
33 | | #include <ktar.h> |
34 | | |
35 | | #include "karchive_fuzzer_common.h" |
36 | | |
37 | | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) |
38 | 32.6k | { |
39 | 32.6k | int argc = 0; |
40 | 32.6k | QCoreApplication a(argc, nullptr); |
41 | | |
42 | 32.6k | QBuffer b; |
43 | 32.6k | b.setData((const char *)data, size); |
44 | | |
45 | 32.6k | #ifdef HANDLER |
46 | 32.6k | KCompressionDevice kd(&b, false, KCompressionDevice::HANDLER); |
47 | 32.6k | KTar ktar(&kd); |
48 | | |
49 | 32.6k | if (ktar.open(QIODevice::ReadOnly)) { |
50 | 23.5k | traverseArchive(ktar.directory()); |
51 | 23.5k | ktar.close(); |
52 | 23.5k | } |
53 | 32.6k | #endif |
54 | | |
55 | 32.6k | return 0; |
56 | 32.6k | } |