feat: add cargo-fuzz targets for transform and CSS scoping#5
Open
jasikpark wants to merge 1 commit intowithastro:feat/rustfrom
Open
feat: add cargo-fuzz targets for transform and CSS scoping#5jasikpark wants to merge 1 commit intowithastro:feat/rustfrom
jasikpark wants to merge 1 commit intowithastro:feat/rustfrom
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds three libfuzzer fuzz targets (via
cargo-fuzz) and a CI workflow:transform_no_panic— arbitrary strings through the full parse → scan → codegen pipelinecss_scope_no_panic— arbitrary CSS throughscope_css()transform_valid_js_output— valid Astro input must produce valid JS output (idempotency/validity check, inspired by ezno's roundtrip fuzz)Usage
cargo install cargo-fuzz cargo +nightly fuzz run transform_no_panic # from repo root cargo +nightly fuzz run css_scope_no_panic cargo +nightly fuzz run transform_valid_js_outputSee
fuzz/README.mdfor full usage including minimization instructions.The
fuzz/crate is its own workspace ([workspace]infuzz/Cargo.toml) so it doesn't affect normal workspace builds.CI
Added
fuzz.ymlwhich runs:fuzz/**Uses
workflow_dispatchwith a configurable fuzz time (default 300s per target). Artifacts are uploaded on failure. Runs as a matrix across all three targets.Bugs found
Running the fuzzer locally and in CI found two bugs:
1. OOM in
withastro/oxcAstro JSX parserMinimized input:
<D}(3 bytes)parse_astro_jsx_expression_container → parse_astro_jsx_elementrecurses without a depth limit, causing unbounded allocation.Upstream issue: withastro/oxc#4
2. Crash in
lightningcssprinter (integer overflow / stack overflow)Minimized input: ~525 bytes of deeply nested
{CSSStyleRule::to_css_base ↔ CssRuleList::to_cssmutual recursion overflows the stack; on Linux this surfaces first asattempt to add with overflowinprinter.rs:219.Upstream issue: parcel-bundler/lightningcss#1155
Notes
libafl_libfuzzer(the modern libFuzzer replacement built on LibAFL) was investigated as a drop-in vialibfuzzer-sys = { version = "0.15", package = "libafl_libfuzzer" }— works on Linux but has a macOS build script issue (can't findllvm-nmin PATH from rustup's llvm-tools). Sticking withlibfuzzer-sys = "0.4"for now.