@@ -39,29 +39,45 @@ git clone --depth=1 https://github.com/bitcoin-core/qa-assets.git
3939 git commit -a -m " Delete fuzz inputs"
4040)
4141
42- git clone --depth=1 https://github.com/bitcoin/bitcoin.git
42+ # TODO: optimize? --no-single-branch increased size from 69M to 170M
43+ # could use ls-remote to list tags and then only fetch tags we need
44+ git clone --depth=1 --no-single-branch https://github.com/bitcoin/bitcoin.git
4345(
4446 cd bitcoin
4547
46- echo " Adding reduced seeds with afl-cmin"
48+ # A fuzz input will be kept if it increases coverage on master or any of the
49+ # last three major versions.
50+ REFS=(" master" )
51+ CURRENT_MAJOR_VERSION=$( git tag --list ' v*' --sort=-v:refname | sed ' s/^v//' | awk -F. ' { print $1 }' | head -1)
52+ PREV_MAJOR_VERSIONS=$( seq $(( CURRENT_MAJOR_VERSION - 3 )) $(( CURRENT_MAJOR_VERSION - 1 )) )
53+ for version in $PREV_MAJOR_VERSIONS ; do
54+ # get latest minor version of each major version
55+ REFS+=($( git tag --list " v$version *" --sort=-v:refname | head -1) )
56+ done
4757
48- rm -rf build_fuzz/
4958 export LDFLAGS=" -fuse-ld=lld"
50- cmake -B build_fuzz \
51- -DCMAKE_C_COMPILER=afl-clang-fast -DCMAKE_CXX_COMPILER=afl-clang-fast++ \
52- -DBUILD_FOR_FUZZING=ON
53- cmake --build build_fuzz -j$( nproc)
54-
55- WRITE_ALL_FUZZ_TARGETS_AND_ABORT=" /tmp/a" " ./build_fuzz/bin/fuzz" || true
56- readarray FUZZ_TARGETS < " /tmp/a"
57- for fuzz_target in ${FUZZ_TARGETS[@]} ; do
58- if [ -d " ../all_inputs/$fuzz_target " ]; then
59- mkdir --parents ../qa-assets/" ${FUZZ_CORPORA_DIR} " /$fuzz_target
59+ for ref in ${REFS[@]} ; do
60+ ref_sha1=$( git rev-parse --short " $ref " )
61+ echo " Adding reduced seeds with afl-cmin on $ref ($ref_sha1 )"
62+
63+ git checkout " $ref "
64+ rm -rf build_fuzz/
65+ cmake -B build_fuzz \
66+ -DCMAKE_C_COMPILER=afl-clang-fast -DCMAKE_CXX_COMPILER=afl-clang-fast++ \
67+ -DBUILD_FOR_FUZZING=ON
68+ cmake --build build_fuzz -j$( nproc)
69+
70+ WRITE_ALL_FUZZ_TARGETS_AND_ABORT=" /tmp/a" " ./build_fuzz/bin/fuzz" || true
71+ readarray FUZZ_TARGETS < " /tmp/a"
72+ for fuzz_target in ${FUZZ_TARGETS[@]} ; do
73+ if [ ! -d " ../all_inputs/$fuzz_target " ]; then
74+ echo " No input corpus for $fuzz_target (ignoring)"
75+ continue
76+ fi
77+ mkdir --parents " ../qa-assets/$FUZZ_CORPORA_DIR /$fuzz_target "
6078 # Allow timeouts and crashes with "-A", "-T all" to use all available cores
61- FUZZ=$fuzz_target afl-cmin -T all -A -i ../all_inputs/$fuzz_target -o ../qa-assets/" ${FUZZ_CORPORA_DIR} " /$fuzz_target -- ./build_fuzz/bin/fuzz
62- else
63- echo " No input corpus for $fuzz_target (ignoring)"
64- fi
79+ FUZZ=$fuzz_target afl-cmin -T all -A -i " ../all_inputs/$fuzz_target " -o " ../qa-assets/$FUZZ_CORPORA_DIR /$fuzz_target " -- ./build_fuzz/bin/fuzz
80+ done
6581 done
6682
6783 (
@@ -70,21 +86,25 @@ git clone --depth=1 https://github.com/bitcoin/bitcoin.git
7086 git commit -m " Reduced inputs for afl-cmin"
7187 )
7288
73- for sanitizer in {" fuzzer" ," fuzzer,address,undefined,integer" }; do
74- echo " Adding reduced seeds for sanitizer=${sanitizer} "
89+ for ref in ${REFS[@]} ; do
90+ git checkout " $ref "
91+ ref_sha1=$( git rev-parse --short $ref )
92+ for sanitizer in {" fuzzer" ," fuzzer,address,undefined,integer" }; do
93+ echo " Adding reduced seeds for sanitizer=${sanitizer} on $ref ($ref_sha1 )"
7594
76- rm -rf build_fuzz/
77- cmake -B build_fuzz \
78- -DCMAKE_C_COMPILER=clang-$LLVM_VERSION -DCMAKE_CXX_COMPILER=clang++-$LLVM_VERSION \
79- -DBUILD_FOR_FUZZING=ON -DSANITIZERS=" $sanitizer "
80- cmake --build build_fuzz -j$( nproc)
95+ rm -rf build_fuzz/
96+ cmake -B build_fuzz \
97+ -DCMAKE_C_COMPILER=clang-$LLVM_VERSION -DCMAKE_CXX_COMPILER=clang++-$LLVM_VERSION \
98+ -DBUILD_FOR_FUZZING=ON -DSANITIZERS=" $sanitizer "
99+ cmake --build build_fuzz -j$( nproc)
81100
82- ( cd build_fuzz; ./test/fuzz/test_runner.py -l DEBUG --par=$( nproc) --m_dir=../../all_inputs ../../qa-assets/" ${FUZZ_CORPORA_DIR} " )
101+ ( cd build_fuzz; ./test/fuzz/test_runner.py -l DEBUG --par=$( nproc) --m_dir=../../all_inputs ../../qa-assets/" ${FUZZ_CORPORA_DIR} " )
83102
84- (
85- cd ../qa-assets
86- git add " ${FUZZ_CORPORA_DIR} "
87- git commit -m " Reduced inputs for ${sanitizer} "
88- )
103+ (
104+ cd ../qa-assets
105+ git add " ${FUZZ_CORPORA_DIR} "
106+ git commit -m " Reduced inputs for ${sanitizer} "
107+ )
108+ done
89109 done
90110)
0 commit comments