#!/usr/bin/env bash # The nightly fuzzing (.gitea/workflows/fuzz.yml); also runs on any Linux # machine with rustup. # bash .gitea/scripts/fuzz.sh setup nightly Rust and cargo-fuzz # bash .gitea/scripts/fuzz.sh run each target for FUZZ_SECONDS (600) # Targets: fuzz/fuzz_targets/, bodies in src/fuzzing.rs. The first corpus # folder (fuzz/corpus/) takes what the run finds; the seeds and the # cases that once broke a target are read as well. set -euo pipefail cd "$(dirname "$0")/../.." export PATH="$HOME/.cargo/bin:$PATH" case "${1:?setup or run}" in setup) bash .gitea/scripts/rust-toolchain.sh stable >/dev/null rustup toolchain install nightly --profile minimal # a fixed version, so the cache keeps one build command -v cargo-fuzz >/dev/null || cargo install cargo-fuzz --version 0.13.1 --locked cargo +nightly --version ;; run) seconds=${FUZZ_SECONDS:-600} # the app's own lock file, so the targets build the versions it runs cp Cargo.lock fuzz/Cargo.lock # No sanitizer: the code is safe Rust, and without AddressSanitizer each # target tries about three times as many inputs. Debug assertions stay # on (overflow checks), as cargo-fuzz builds by default. nice -n 19 cargo +nightly fuzz build -O -s none failed=() for target in $(cargo +nightly fuzz list); do mkdir -p "fuzz/corpus/$target" "fuzz/artifacts/$target" echo "== $target, ${seconds} s" # -timeout: one input taking 10 s is a finding; -rss_limit_mb: so is # one that needs 2 GB (cnx01 gives the app 1 GB in all) if ! nice -n 19 cargo +nightly fuzz run -O -s none "$target" \ "fuzz/corpus/$target" "fuzz/seeds/$target" "tests/fuzz_cases/$target" -- \ -max_total_time="$seconds" -timeout=10 -rss_limit_mb=2048 -max_len=1048576 \ -print_final_stats=1; then failed+=("$target") fi done du -sh fuzz/corpus/* || true if [ ${#failed[@]} -gt 0 ]; then echo "found something: ${failed[*]} (artifact fuzz-findings)" ls -l fuzz/artifacts/*/ || true exit 1 fi ;; esac