-
Notifications
You must be signed in to change notification settings - Fork 10
test(fuzz): revive the fuzz target and run it nightly in CI #281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d0bb614
test(fuzz): drive async resolve, widen options, add nightly CI
stormslowly 2122994
ci(fuzz): open an issue when a scheduled run crashes
stormslowly 5fc2f0a
ci(fuzz): label the crash issue with fuzz-crash
stormslowly 1d4dda3
ci(fuzz): [temp] trigger on PRs touching fuzz files
stormslowly 96750a3
fix(ci): build cargo-fuzz from source to avoid musl target default
stormslowly 33b29b5
ci(fuzz): drop the temporary pull_request trigger
stormslowly 54311e5
ci(fuzz): run from repo root so the harness sees the real tree
stormslowly 6578fdd
ci(fuzz): [temp] re-add pull_request trigger to validate root-cwd run
stormslowly 0d83d2e
Revert "ci(fuzz): run from repo root" and drop temp PR trigger
stormslowly 80221dd
Merge remote-tracking branch 'origin/main' into fuzz/revive-target-an…
stormslowly File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| name: Fuzz | ||
|
|
||
| on: | ||
| schedule: | ||
| # Nightly short fuzz run at 03:00 UTC | ||
| - cron: "0 3 * * *" | ||
| workflow_dispatch: | ||
| inputs: | ||
| max_total_time: | ||
| description: "Seconds to run the fuzzer" | ||
| default: "300" | ||
|
|
||
| concurrency: | ||
| group: ${{ github.workflow }}-${{ github.ref }} | ||
| cancel-in-progress: true | ||
|
|
||
| permissions: | ||
| contents: read | ||
|
|
||
| defaults: | ||
| run: | ||
| shell: bash | ||
|
|
||
| jobs: | ||
| fuzz: | ||
| name: Nightly Fuzz | ||
| runs-on: ubuntu-latest | ||
| permissions: | ||
| contents: read | ||
| issues: write # open an issue when a scheduled run finds a crash | ||
| steps: | ||
| - uses: taiki-e/checkout-action@7d1e50e93dc4fb3bba58f85018fadf77898aee8b # v1.4.2 | ||
|
|
||
| - uses: actions-rust-lang/setup-rust-toolchain@46268bd060767258de96ed93c1251119784f2ab6 # v1.16.1 | ||
| with: | ||
| # cargo-fuzz requires a nightly toolchain | ||
| toolchain: nightly | ||
| cache-key: fuzz | ||
|
|
||
| # Build from source: the binstall musl binary of cargo-fuzz defaults its | ||
| # build target to musl, whose std isn't installed on the gnu runner. | ||
| - run: cargo install cargo-fuzz | ||
|
|
||
| # Carry the corpus across runs so nightly fuzzing keeps making progress | ||
| # instead of starting cold every night. | ||
| - uses: actions/cache@5a3ec84eff668545956fd18022155c47e93e2684 # v4.2.3 | ||
| with: | ||
| path: fuzz/corpus | ||
| key: fuzz-corpus-${{ github.run_id }} | ||
| restore-keys: fuzz-corpus- | ||
|
|
||
| - name: Run fuzzer | ||
| working-directory: fuzz | ||
| run: cargo +nightly fuzz run --sanitizer none resolver -- -only_ascii=1 -max_total_time=${{ inputs.max_total_time || '300' }} | ||
|
|
||
| - name: Upload crash artifacts | ||
| if: failure() | ||
| uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 | ||
| with: | ||
| name: fuzz-artifacts | ||
| path: fuzz/artifacts | ||
| if-no-files-found: ignore | ||
|
|
||
| # Only scheduled runs file an issue; manual workflow_dispatch failures don't. | ||
| - name: Open issue on scheduled crash | ||
| if: failure() && github.event_name == 'schedule' | ||
| env: | ||
| GH_TOKEN: ${{ github.token }} | ||
| RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} | ||
| run: | | ||
| # Idempotent: creates the label, or updates it if it already exists. | ||
| gh label create fuzz-crash --force --color B60205 \ | ||
| --description "Crash found by the nightly fuzz run" | ||
| # Skip if a crash issue is already open, so a persisting crash isn't re-filed nightly. | ||
| if [ "$(gh issue list --state open --label fuzz-crash --json number --jq 'length')" -gt 0 ]; then | ||
| echo "An open fuzz crash issue already exists; skipping." | ||
| exit 0 | ||
| fi | ||
| gh issue create \ | ||
| --title "Nightly fuzz crash ($(date -u +%F))" \ | ||
| --label fuzz-crash \ | ||
| --body "The nightly fuzz run found a crash. Download the reproducing input from the **fuzz-artifacts** artifact on the failed run. | ||
|
|
||
| Run: $RUN_URL" | ||
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,14 +1,44 @@ | ||
| #![no_main] | ||
|
|
||
| use libfuzzer_sys::fuzz_target; | ||
| use rspack_resolver::Resolver; | ||
| use rspack_resolver::{AliasValue, ResolveOptions, Resolver}; | ||
|
|
||
| fuzz_target!(|data: &[u8]| { | ||
| if let Ok(s) = std::str::from_utf8(data) { | ||
| if s.chars().all(|s| !s.is_control()) { | ||
| let resolver = Resolver::default(); | ||
| let cwd = std::env::current_dir().unwrap(); | ||
| let _ = resolver.resolve(cwd, &s); | ||
| } | ||
| // First byte drives a few resolver-option toggles; the rest is the specifier. | ||
| let Some((&cfg, rest)) = data.split_first() else { | ||
| return; | ||
| }; | ||
| let Ok(specifier) = std::str::from_utf8(rest) else { | ||
| return; | ||
| }; | ||
| if specifier.chars().any(char::is_control) { | ||
| return; | ||
| } | ||
|
|
||
| let condition_names = if cfg & 0b001 == 0 { | ||
| vec!["node".into(), "import".into()] | ||
| } else { | ||
| vec!["node".into(), "require".into()] | ||
| }; | ||
| let extensions = if cfg & 0b010 == 0 { | ||
| vec![".js".into(), ".json".into(), ".node".into()] | ||
| } else { | ||
| vec![".ts".into(), ".tsx".into(), ".js".into()] | ||
| }; | ||
| let alias = if cfg & 0b100 == 0 { | ||
| vec![] | ||
| } else { | ||
| vec![("@".into(), vec![AliasValue::Path("./src".into())])] | ||
| }; | ||
|
|
||
| let resolver = Resolver::new(ResolveOptions { | ||
| condition_names, | ||
| extensions, | ||
| alias, | ||
| symlinks: cfg & 0b1000 == 0, | ||
| ..ResolveOptions::default() | ||
| }); | ||
| let cwd = std::env::current_dir().unwrap(); | ||
|
stormslowly marked this conversation as resolved.
|
||
| // `resolve` is async; the future must be driven or the body is a no-op. | ||
| let _ = futures::executor::block_on(resolver.resolve(cwd, specifier)); | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.