|
| 1 | +# Copyright (c) 2025 Erick Bourgeois, firestoned |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | +# |
| 4 | +# Short-duration fuzzing of 5-Spot's string parsers on every PR and push. |
| 5 | +# |
| 6 | +# Each target runs for 60 seconds against libFuzzer via cargo-fuzz. This is a |
| 7 | +# credible smoke-fuzz, not continuous fuzzing — the Scorecard FuzzingID check |
| 8 | +# only requires that some fuzzing infrastructure exists; follow-up work is |
| 9 | +# tracked in ~/dev/roadmaps/5spot-code-scanning-remediation.md § Phase 8 to |
| 10 | +# integrate with OSS-Fuzz for continuous coverage. |
| 11 | +# |
| 12 | +# Requires nightly Rust (libfuzzer-sys uses nightly-only build-script hooks). |
| 13 | + |
| 14 | +name: Fuzz |
| 15 | + |
| 16 | +on: |
| 17 | + pull_request: |
| 18 | + branches: |
| 19 | + - main |
| 20 | + paths: |
| 21 | + - 'src/**/*.rs' |
| 22 | + - 'Cargo.toml' |
| 23 | + - 'Cargo.lock' |
| 24 | + - 'fuzz/**' |
| 25 | + - '.github/workflows/fuzz.yaml' |
| 26 | + push: |
| 27 | + branches: |
| 28 | + - main |
| 29 | + paths: |
| 30 | + - 'src/**/*.rs' |
| 31 | + - 'Cargo.toml' |
| 32 | + - 'Cargo.lock' |
| 33 | + - 'fuzz/**' |
| 34 | + - '.github/workflows/fuzz.yaml' |
| 35 | + |
| 36 | +permissions: |
| 37 | + contents: read |
| 38 | + |
| 39 | +env: |
| 40 | + # Override the cross-compilation linkers set in .cargo/config.toml. |
| 41 | + # cargo-fuzz builds with --target x86_64-unknown-linux-gnu, which picks up |
| 42 | + # the macOS cross-compiler setting in .cargo/config.toml — that tool is |
| 43 | + # not on Linux CI runners, so builds fail with |
| 44 | + # `linker x86_64-unknown-linux-gnu-gcc not found`. `cc` is the native GCC. |
| 45 | + CARGO_TARGET_X86_64_UNKNOWN_LINUX_GNU_LINKER: cc |
| 46 | + CARGO_TARGET_AARCH64_UNKNOWN_LINUX_GNU_LINKER: cc |
| 47 | + |
| 48 | +jobs: |
| 49 | + fuzz: |
| 50 | + name: 🎲 Fuzz ${{ matrix.target }} |
| 51 | + runs-on: ubuntu-latest |
| 52 | + strategy: |
| 53 | + fail-fast: false |
| 54 | + matrix: |
| 55 | + target: |
| 56 | + - parse_duration |
| 57 | + - parse_day_ranges |
| 58 | + - parse_hour_ranges |
| 59 | + steps: |
| 60 | + - name: Checkout code |
| 61 | + uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2 |
| 62 | + |
| 63 | + - name: Install nightly Rust toolchain |
| 64 | + uses: dtolnay/rust-toolchain@29eef336d9b2848a0b548edc03f92a220660cdb8 # stable (moving ref — re-pin quarterly) |
| 65 | + with: |
| 66 | + toolchain: nightly |
| 67 | + |
| 68 | + - name: Install cargo-fuzz |
| 69 | + run: cargo install cargo-fuzz --locked |
| 70 | + |
| 71 | + - name: Cache cargo dependencies |
| 72 | + uses: firestoned/github-actions/rust/cache-cargo@53b483254bc648903c364ee3c73a546d0936a91e # v1.3.6 |
| 73 | + |
| 74 | + - name: Run fuzz target (60 s) |
| 75 | + working-directory: fuzz |
| 76 | + run: cargo +nightly fuzz run ${{ matrix.target }} -- -max_total_time=60 |
| 77 | + |
| 78 | + - name: Upload crash artifacts on failure |
| 79 | + if: failure() |
| 80 | + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 |
| 81 | + with: |
| 82 | + name: fuzz-crash-${{ matrix.target }} |
| 83 | + path: fuzz/artifacts/${{ matrix.target }}/ |
| 84 | + if-no-files-found: ignore |
0 commit comments