Fuzz Testing #244
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Fuzz Testing | |
| # Run fuzzing on schedule and manual trigger | |
| # Fuzzing is too slow for every PR, so we run it nightly | |
| on: | |
| schedule: | |
| # Run at 3 AM UTC every day | |
| - cron: '0 3 * * *' | |
| workflow_dispatch: | |
| inputs: | |
| duration: | |
| description: 'Fuzzing duration in seconds per target (positive integer)' | |
| required: false | |
| default: '300' | |
| permissions: | |
| contents: read | |
| env: | |
| CARGO_TERM_COLOR: always | |
| jobs: | |
| fuzz: | |
| name: Fuzz Test | |
| runs-on: ubuntu-latest | |
| strategy: | |
| fail-fast: false | |
| matrix: | |
| target: [parser_fuzz, lexer_fuzz, analyze_fuzz, arithmetic_fuzz, glob_fuzz] | |
| steps: | |
| - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 | |
| - name: Install Rust nightly | |
| uses: dtolnay/rust-toolchain@5b842231ba77f5c045dba54ac5560fed2db780e2 # nightly | |
| - name: Install cargo-fuzz | |
| run: cargo install cargo-fuzz --locked | |
| - name: Cache fuzz corpus | |
| uses: actions/cache@55cc8345863c7cc4c66a329aec7e433d2d1c52a9 # v5 | |
| with: | |
| path: crates/bashkit/fuzz/corpus | |
| key: fuzz-corpus-${{ matrix.target }}-${{ github.sha }} | |
| restore-keys: | | |
| fuzz-corpus-${{ matrix.target }}- | |
| - name: Run fuzzer - ${{ matrix.target }} | |
| working-directory: crates/bashkit | |
| env: | |
| DURATION_INPUT: ${{ github.event.inputs.duration || '300' }} | |
| run: | | |
| # Validate duration is a positive integer before use (prevents shell injection | |
| # from workflow_dispatch inputs being interpolated directly into the shell). | |
| # ^[1-9][0-9]*$ rejects 0, negatives, and leading zeros (avoids bash octal | |
| # arithmetic ambiguity, e.g. "09" would error on -eq comparisons). | |
| if ! [[ "$DURATION_INPUT" =~ ^[1-9][0-9]*$ ]]; then | |
| echo "::error::duration must be a positive integer with no leading zeros, got: $DURATION_INPUT" | |
| exit 1 | |
| fi | |
| cargo +nightly fuzz run ${{ matrix.target }} -- \ | |
| -max_total_time="$DURATION_INPUT" \ | |
| -print_final_stats=1 | |
| - name: Upload crash artifacts | |
| if: failure() | |
| uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7 | |
| with: | |
| name: fuzz-crashes-${{ matrix.target }} | |
| path: | | |
| crates/bashkit/fuzz/artifacts/${{ matrix.target }} | |
| retention-days: 30 |