Skip to content

Commit dbc0042

Browse files
authored
Split KArchive fuzzer and add dict files (#13633)
1 parent b0ce00b commit dbc0042

14 files changed

+327
-68
lines changed

projects/karchive/Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ RUN git clone --depth 1 --branch=dev git://code.qt.io/qt/qtbase.git
2525
RUN git clone --depth 1 --branch=dev git://code.qt.io/qt/qttools.git
2626
RUN git clone --depth 1 -b master https://invent.kde.org/frameworks/extra-cmake-modules.git
2727
RUN git clone --depth 1 -b master https://invent.kde.org/frameworks/karchive.git
28-
COPY build.sh karchive_fuzzer.cc $SRC/
28+
COPY build.sh karchive_fuzzer.cc karchive_fuzzer_common.h kcompressiondevice_fuzzer.cc dict $SRC/
2929
WORKDIR $SRC/karchive

projects/karchive/build.sh

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,40 @@ cmake . -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTING=OFF
8989
make install -j$(nproc)
9090

9191
# Build karchive_fuzzer
92-
$CXX $CXXFLAGS -fPIC -std=c++17 $SRC/karchive_fuzzer.cc -o $OUT/karchive_fuzzer -I /usr/include/QtCore/ -I /usr/local/include/KF6/KArchive -lQt6Core -lm -lQt6BundledPcre2 -ldl -lpthread $LIB_FUZZING_ENGINE /usr/local/lib/libz.a -lKF6Archive /usr/local/lib/libbz2.a -llzma /usr/local/lib/libzstd.a /usr/local/lib64/libcrypto.a
92+
HANDLER_TYPES="K7Zip 7z karchive_fuzzer
93+
KAr ar karchive_fuzzer
94+
KTar tar karchive_fuzzer
95+
KZip zip karchive_fuzzer
96+
GZip tar_gz kcompressiondevice_fuzzer
97+
BZip2 tar_bz2 kcompressiondevice_fuzzer
98+
Xz tar_xz kcompressiondevice_fuzzer
99+
Zstd tar_zst kcompressiondevice_fuzzer
100+
Lz tar_lz kcompressiondevice_fuzzer"
93101

94-
cd $SRC
95-
find . -name "*.gz" -o -name "*.zip" -o -name "*.xz" -o -name "*.tar" -o -name "*.7z" | zip -q $OUT/karchive_fuzzer_seed_corpus.zip -@
102+
echo "$HANDLER_TYPES" | while read class format source_file; do
103+
(
104+
fuzz_target_name=k${format}_fuzzer
105+
fuzz_target_flags="-DHANDLER=$class"
106+
107+
if [[ "$class" == "K7Zip" ]]; then # KZip in future?
108+
fuzz_target_flags+=" -DUSE_PASSWORD"
109+
fi
110+
111+
$CXX $CXXFLAGS -fPIC $fuzz_target_flags -std=c++17 $SRC/$source_file.cc -o $OUT/$fuzz_target_name \
112+
-I /usr/include/QtCore/ -I /usr/local/include/KF6/KArchive -lQt6Core -lm -lQt6BundledPcre2 \
113+
-ldl -lpthread $LIB_FUZZING_ENGINE /usr/local/lib/libz.a -lKF6Archive /usr/local/lib/libbz2.a \
114+
-llzma /usr/local/lib/libzstd.a /usr/local/lib64/libcrypto.a
115+
116+
extension="${format/_/.}" # Replace _ with .
117+
files=$(find . -name "*.${extension}")
118+
if [ -n "$files" ]; then
119+
echo "$files" | zip -q $OUT/${fuzz_target_name}_seed_corpus.zip -@
120+
else
121+
echo "no files found with extension $extension for $fuzz_target_name seed corpus"
122+
fi
123+
124+
if [ -f "$SRC/$fuzz_target_name.dict" ]; then
125+
cp "$SRC/$fuzz_target_name.dict" $OUT/
126+
fi
127+
)
128+
done
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# SPDX-FileCopyrightText: 2025 Azhar Momin <azhar.momin@kdemail.net>
2+
# SPDX-License-Identifier: CC0-1.0
3+
4+
magic="7z\xBC\xAF\x27\x1C"
5+
6+
# Header types
7+
end="\x00"
8+
header="\x01"
9+
archive_properties="\x02"
10+
additional_streams_info="\x03"
11+
main_streams_info="\x04"
12+
files_info="\x05"
13+
pack_info="\x06"
14+
unpack_info="\x07"
15+
substreams_info="\x08"
16+
size="\x09"
17+
crc="\x0A"
18+
folder="\x0B"
19+
coders_unpack_size="\x0C"
20+
num_unpack_stream="\x0D"
21+
empty_stream="\x0E"
22+
empty_file="\x0F"
23+
anti="\x10"
24+
name="\x11"
25+
ctime="\x12"
26+
atime="\x13"
27+
mtime="\x14"
28+
attributes="\x15"
29+
comment="\x16"
30+
encoded_header="\x17"
31+
start_pos="\x18"
32+
dummy="\x19"
33+
34+
# Method IDs
35+
lzma2="\x21"
36+
lzma="\x03\x01\x01"
37+
bcj="\x03\x03\x01\x03"
38+
bcj2="\x03\x03\x01\x1B"
39+
ppmd="\x03\x04\x01"
40+
bzip2="\x04\x02\x02"
41+
aes="\x06\xF1\x07\x01"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# SPDX-FileCopyrightText: 2025 Azhar Momin <azhar.momin@kdemail.net>
2+
# SPDX-License-Identifier: CC0-1.0
3+
4+
magic="!<arch>\\n"
5+
file_magic="`\\n"
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# SPDX-FileCopyrightText: 2025 Azhar Momin <azhar.momin@kdemail.net>
2+
# SPDX-License-Identifier: CC0-1.0
3+
4+
magic="ustar"
5+
version="00"
6+
7+
magic="BZ"
8+
version_bzip2="h"
9+
version_bzip1="0"
10+
11+
compressed_magic="\x31\x41\x59\x26\x53\x59"
12+
eos_magic="\x17\x72\x45\x38\x50\x90"
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# SPDX-FileCopyrightText: 2025 Azhar Momin <azhar.momin@kdemail.net>
2+
# SPDX-License-Identifier: CC0-1.0
3+
4+
magic="ustar"
5+
version="00"
6+
7+
# Interesting typeflags
8+
"5"
9+
"D"
10+
"x"
11+
"g"
12+
"1"
13+
14+
longlink="././@LongLink"
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# SPDX-FileCopyrightText: 2025 Azhar Momin <azhar.momin@kdemail.net>
2+
# SPDX-License-Identifier: CC0-1.0
3+
4+
magic="ustar"
5+
version="00"
6+
7+
magic="\x1F\x8B"
8+
9+
deflate="\x08"
10+
11+
# File Flags
12+
ftxt="\x01"
13+
fhcrc="\x02"
14+
fextra="\x04"
15+
fname="\x08"
16+
fcomment="\x10"
17+
fall="\x1F"
18+
19+
# Operating System
20+
fat="\x00"
21+
amiga="\x01"
22+
vms="\x02"
23+
unix="\x03"
24+
vm_cms="\x04"
25+
atari_tos="\x05"
26+
hpfs="\x06"
27+
mac="\x07"
28+
zsystem="\x08"
29+
cp_m="\x09"
30+
tops20="\x0A"
31+
ntfs="\x0B"
32+
qdos="\x0C"
33+
acorn_riscos="\x0D"
34+
unknown="\xFF"
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# SPDX-FileCopyrightText: 2025 Azhar Momin <azhar.momin@kdemail.net>
2+
# SPDX-License-Identifier: CC0-1.0
3+
4+
magic="ustar"
5+
version="00"
6+
7+
magic="LZIP"
8+
version_old="\x00"
9+
version="\x01"
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# SPDX-FileCopyrightText: 2025 Azhar Momin <azhar.momin@kdemail.net>
2+
# SPDX-License-Identifier: CC0-1.0
3+
4+
magic="ustar"
5+
version="00"
6+
7+
magic="\x5D\x37\x7A\x58\x5A\x00"
8+
footer_magic="\x59\x5A"
9+
10+
check_none="\x00\x00"
11+
check_crc32="\x01\x00"
12+
check_crc64="\x04\x00"
13+
check_sha256="\x0A\x00"
14+
15+
# Filter IDs
16+
lzma2="\x21"
17+
delta="\x03"
18+
x86="\x04"
19+
powerpc="\x05"
20+
ia64="\x06"
21+
arm="\x07"
22+
armthumb="\x08"
23+
sparc="\x09"
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# SPDX-FileCopyrightText: 2025 Azhar Momin <azhar.momin@kdemail.net>
2+
# SPDX-License-Identifier: CC0-1.0
3+
4+
magic="ustar"
5+
version="00"
6+
7+
magic="\x28\xB5\x2F\xFD"
8+
9+
# Skippable Frames
10+
"\x50\x2A\x4D\x18"
11+
"\x51\x2A\x4D\x18"
12+
"\x52\x2A\x4D\x18"
13+
"\x53\x2A\x4D\x18"
14+
"\x54\x2A\x4D\x18"
15+
"\x55\x2A\x4D\x18"
16+
"\x56\x2A\x4D\x18"
17+
"\x57\x2A\x4D\x18"
18+
"\x58\x2A\x4D\x18"
19+
"\x59\x2A\x4D\x18"
20+
"\x5A\x2A\x4D\x18"
21+
"\x5B\x2A\x4D\x18"
22+
"\x5C\x2A\x4D\x18"
23+
"\x5D\x2A\x4D\x18"
24+
"\x5E\x2A\x4D\x18"
25+
"\x5F\x2A\x4D\x18"

0 commit comments

Comments
 (0)