name: Fuzz
on:
push:
branches: [main]
pull_request:
schedule:
- cron: '39 3 * * 5'
permissions:
contents: read
issues: write
env:
CARGO_TERM_COLOR: always
FUZZ_DURATION: 600
FUZZ_TARGETS: |
parse_file
roundtrip_simple
jobs:
cargo-fuzz:
name: Fuzz (cargo-fuzz)
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Install Rust nightly
uses: dtolnay/rust-toolchain@3c5f7ea28cd621ae0bf5283f0e981fb97b8a7af9 with:
toolchain: nightly
targets: x86_64-unknown-linux-gnu
- uses: Swatinem/rust-cache@v2
with:
key: cargo-fuzz
- name: Install cargo-fuzz
uses: taiki-e/install-action@920ab1831fbf4fb3ef75c8ead83556c918bb7290 with:
tool: cargo-fuzz
- name: Use PR smoke duration
if: github.event_name == 'pull_request'
run: |
set -euo pipefail
echo "FUZZ_DURATION=30" >> "${GITHUB_ENV}"
- name: Run streaming differential fuzz target
run: |
# Pin the gnu target: cargo-fuzz ships as a musl-static binary, so it
# otherwise defaults to the musl target, whose static libc the address
# sanitizer cannot link against.
cargo +nightly fuzz run streaming_differential fuzz/corpus/parse_file \
--target x86_64-unknown-linux-gnu -- -max_total_time="${FUZZ_DURATION}" -rss_limit_mb=4096
- name: Run fuzz targets
run: |
set -euo pipefail
for target in ${FUZZ_TARGETS}; do
echo "::group::cargo +nightly fuzz run ${target}"
cargo +nightly fuzz run "${target}" \
--target x86_64-unknown-linux-gnu -- -max_total_time="${FUZZ_DURATION}" -rss_limit_mb=4096
echo "::endgroup::"
done
- name: Upload crash artifacts
id: upload-crash-artifacts
if: failure()
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a with:
name: fuzz-artifacts
path: fuzz/artifacts
retention-days: 14
if-no-files-found: ignore
- name: Create scheduled failure issue
if: failure() && github.event_name == 'schedule'
env:
GH_TOKEN: ${{ github.token }}
ARTIFACT_URL: ${{ steps.upload-crash-artifacts.outputs.artifact-url }}
run: |
set -euo pipefail
{
echo "Weekly fuzzing failed."
echo
echo "Run: ${GITHUB_SERVER_URL}/${GITHUB_REPOSITORY}/actions/runs/${GITHUB_RUN_ID}"
if [[ -n "${ARTIFACT_URL}" ]]; then
echo "Fuzz artifacts: ${ARTIFACT_URL}"
fi
echo
echo "To reproduce, download and extract fuzz-artifacts at the repo root, then run:"
echo
echo '```sh'
echo 'cargo +nightly fuzz run <target> fuzz/artifacts/<target>/<crash-file> --target x86_64-unknown-linux-gnu -- -rss_limit_mb=4096'
echo '```'
} > issue.md
gh issue create \
--title "Scheduled fuzzing failed" \
--body-file issue.md \
--label bug