/src/karchive/autotests/ossfuzz/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 | | #ifndef DEVICE |
29 | | #error "DEVICE is not defined" |
30 | | #endif |
31 | | |
32 | | #include <QBuffer> |
33 | | #include <QCoreApplication> |
34 | | |
35 | | #include <kcompressiondevice.h> |
36 | | #include <ktar.h> |
37 | | |
38 | | #include "karchive_fuzzer_common.h" |
39 | | |
40 | | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) |
41 | 24.9k | { |
42 | 24.9k | int argc = 0; |
43 | 24.9k | QCoreApplication a(argc, nullptr); |
44 | | |
45 | 24.9k | QBuffer b; |
46 | 24.9k | b.setData((const char *)data, size); |
47 | | |
48 | 24.9k | KCompressionDevice kd(&b, false, KCompressionDevice::DEVICE); |
49 | 24.9k | KTar ktar(&kd); |
50 | | |
51 | 24.9k | if (ktar.open(QIODevice::ReadOnly)) { |
52 | 16.1k | traverseArchive(ktar.directory()); |
53 | 16.1k | ktar.close(); |
54 | 16.1k | } |
55 | | |
56 | 24.9k | return 0; |
57 | 24.9k | } |