1 /*
2 # Copyright 2019 Google Inc.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 #
16 ################################################################################
17 */
18
19 /*
20 Usage:
21 python infra/helper.py build_image karchive
22 python infra/helper.py build_fuzzers --sanitizer undefined|address|memory karchive
23 python infra/helper.py run_fuzzer karchive karchive_fuzzer
24 */
25
26
27 #include <QBuffer>
28 #include <QCoreApplication>
29 #include <QVector>
30
31 #include <KF5/KArchive/k7zip.h>
32 #include <KF5/KArchive/ktar.h>
33 #include <KF5/KArchive/kzip.h>
34 #include <KF5/KArchive/kar.h>
35 #include <KF5/KArchive/kcompressiondevice.h>
36
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)37 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
38 {
39 int argc = 0;
40 QCoreApplication a(argc, nullptr);
41
42 QBuffer b;
43 b.setData((const char *)data, size);
44
45 std::unique_ptr<KCompressionDevice> gzipKD(new KCompressionDevice(&b, false, KCompressionDevice::GZip));
46 std::unique_ptr<KCompressionDevice> bzipKD(new KCompressionDevice(&b, false, KCompressionDevice::BZip2));
47 std::unique_ptr<KCompressionDevice> xzKD(new KCompressionDevice(&b, false, KCompressionDevice::Xz));
48
49 const QVector<KArchive*> handlers = {
50 new K7Zip(&b),
51 new KTar(&b),
52 new KTar(gzipKD.get()),
53 new KTar(bzipKD.get()),
54 new KTar(xzKD.get()),
55 new KZip(&b),
56 new KAr(&b)
57 };
58
59 for (KArchive *h : handlers) {
60 b.reset();
61 h->open(QIODevice::ReadOnly);
62 h->close();
63 }
64
65 qDeleteAll(handlers);
66
67 return 0;
68 }
69