Results of fuzz-testing the xz compression library (https://github.com/tukaani-project/xz).
Version tested: v5.4.6 (https://github.com/tukaani-project/xz/releases/tag/v5.4.6). Compiled with instrumentation and tested with AflPlusPlus (https://aflplus.plus/).
build xz distribution with AFL instrumentation.
- Prerequisites: install C & C++ compilers, make, afl++; Download and unpack the distro.
- In the distro dir: setup env variables to use AFL-instrumented compilers and run configure:
CC=path/to/afl/afl-gcc CXX=path/to/afl/afl-g++ ./configure --disable-shared
(in one line). Flag--disable-shared
gets the binary installed into the building dir. - Assemble the binary by
make clean all
. - The target binary will appear in src/xz subfolder
The seeds_dir contains initial test cases to be compressed, seeds_xz_dir contains test cases of compressed files to be decompressed. They are: small code example, a binary executable, a text file containing all 256 ASCII characters, a picture, a voice recorder file and an already compressed file.
To fuzz-test decompression wuth afl: /path/to/afl/afl-fuzz -i seeds_xz_dir/ -o output_dir/ -- path/to/distro/src/xz/xz -d @@
. Flag -d stands for decompression.
Fuzzing was stopped once no new paths were found in 15 minutes. In 2h 47min, 443 paths were found, and zero crashes.
To calculate code coverage, another distribution is compiled from sources with --coverage flags. Then, corpuses from output_dir/default/queue
which were generated during fuzzing phase, are executed on a compiled binary.
CC="gcc --coverage" CXX="g++ --coverage" ./configure --disable-shared
make clean all
cd path/to/src/xz
(directory with xz binary compiled with coverage)for file in path/to/output_dir/default/queue/*; do ./xz -d $file; done
(execute all paths)
When executing, .gcda files are created, they can be found in a distribution dir by find -name *.gcda
- they are bitmaps with data about executed paths.
Lastly, generate coverage report with
lcov -c -d . -o xz_coverage
(from same distr dir, generates file with line coverage by file data)genhtml -o coverage_report xz_coverage
(generates pretty html file)
overall line coverage: 15.4%, overall function coverage: 23.0%
When navigating into file, blue lines are executed ones, red are not. White are not-executable lines.
as there are sources in the resulting report, you may not want to include them. To delete them, run:
find -name *.gcov.html | xargs rm