name: fuzz # Nightly cargo-fuzz harness. The `fuzz/` crate (PR #103) is a detached # workspace with four libFuzzer targets over the untrusted-input parsers — # RatchetState::from_bytes/decrypt, qr::decode, dispatch::classify, file::decode. # Nothing else in CI compiles this crate, so the targets bit-rot silently. # # This used to be a job in `ci.yml`, which meant it inherited that workflow's # PR path filter (`src/**`, `crates/**`, `tests/**`, `Cargo.lock`, …) and ran # on almost every push: 80 of 84 recorded runs touched neither `fuzz/` nor # `scripts/run-fuzz.sh`. Each one also paid `rustup toolchain install nightly` # plus `cargo install cargo-fuzz --locked` before it could do 15 seconds of # fuzzing. Bit-rot is a slow signal; a PR gate is the wrong shape for it. # # It is a scheduled job now. `workflow_dispatch` is the manual escape hatch # (a parser change deserves a longer run than the 15s below — raise FUZZ_SECS # in the dispatch env for that). on: schedule: # 03:30 UTC nightly. Forgejo cron is UTC; off the hour on purpose so it # does not pile onto the 06:17 arti-watch slot. - cron: "30 3 * * *" workflow_dispatch: # Never two fuzz runs at once: they hold the shared fuzz registry and target # volumes, and a second one is a `docker Conflict` plus a cold rebuild. concurrency: group: onionwire-ci-pi-fuzz cancel-in-progress: false env: CARGO_TERM_COLOR: never # Base image only: the job switches to nightly before it compiles. Kept on # the same tag as ci.yml so a step that forgets `+nightly` does not die in # `tapes` on 1.91 (`VecDeque::pop_front_if`). RUST_IMAGE: rust:1.98-bookworm # The build needs a release profile + debug=line-tables-only, so it must not # thrash the test/sdk target volumes and needs its own registry cache. FUZZ_REGISTRY_VOLUME: onionwire-cargo-registry-fuzz FUZZ_TARGET_VOLUME: onionwire-target-ci-fuzz FUZZ_BUILD_CONTAINER: onionwire-ci-fuzz-${{ github.run_id }} # libFuzzer writes its -fork dir into TMPDIR; point it at the target volume so # a host tmpfs quota can't OOM-kill the builder. FUZZ_TMP_DIR: /target/tmp # Per-build CPU budget. The Pi has 4 cores shared with whatever CI run is # live, so 2 is what leaves headroom. FUZZ_SECS: "15" FUZZ_JOBS: "2" jobs: build: runs-on: docker timeout-minutes: 120 steps: - name: Checkout uses: https://code.forgejo.org/actions/checkout@v4 - name: build + run fuzz targets run: | set -euo pipefail cd "${GITHUB_WORKSPACE}" echo "workspace: $GITHUB_WORKSPACE" docker volume create "$FUZZ_REGISTRY_VOLUME" > /dev/null docker volume create "$FUZZ_TARGET_VOLUME" > /dev/null docker rm -f "$FUZZ_BUILD_CONTAINER" > /dev/null 2>&1 || true # Build AND run in ONE container. Splitting them into two # `docker create` calls gives the second one a fresh image, and the # cargo-fuzz binary installed in the first is gone with it # (PR #106 fixed this; PR #106/#107 added the PATH export too). docker create --name "$FUZZ_BUILD_CONTAINER" -i \ -e CARGO_TARGET_DIR=/target \ -e CARGO_BUILD_JOBS=2 \ -e CARGO_TERM_COLOR=never \ -e TMPDIR=/target/tmp \ -e RUSTUP_HOME=/usr/local/rustup \ -e CARGO_HOME=/usr/local/cargo \ -e FUZZ_SECS="$FUZZ_SECS" \ -e FUZZ_JOBS="$FUZZ_JOBS" \ -v "$FUZZ_REGISTRY_VOLUME":/usr/local/cargo/registry \ -v "$FUZZ_TARGET_VOLUME":/target \ -w /src \ "$RUST_IMAGE" \ sh -euxc 'mkdir -p /src /target/tmp && tar xzf - -C /src && cd /src \ && apt-get update \ && apt-get install -y --no-install-recommends pkg-config libssl-dev cmake build-essential \ && rustup toolchain install nightly --profile minimal \ && rustup default nightly \ && cargo install cargo-fuzz --locked \ && export PATH="/usr/local/cargo/bin:$PATH" \ && cd /src/fuzz \ && cargo +nightly fuzz build \ && cargo +nightly fuzz list \ && bash /src/scripts/run-fuzz.sh' # A fresh Docker volume has no tmp/ subdirectory, and rustup fails # with "error creating temp directory: No such file or directory" if # TMPDIR points into one that does not exist yet. tar czf - --exclude=./target --exclude=./.git --exclude=./.worktrees . \ | docker start -a -i "$FUZZ_BUILD_CONTAINER" docker rm -f "$FUZZ_BUILD_CONTAINER" > /dev/null