Repository navigation
test(js): the parser's limits were untested, and it had no fuzz target - #189
Open
jamesconwaydev wants to merge 2 commits into
Open
jamesconwaydev wants to merge 2 commits into
jamesconwaydev wants to merge 2 commits into
Conversation
The parser counted its depth and spent its step budget, but no test showed that hostile input stops there, and only the lexer was fuzzed. - tests/limits.rs: a 1,000,000-deep `((((` fails with `too-deep` on a 1 MB thread, as does nesting of 20 other kinds, and nesting inside the limit parses and writes out. 23 kinds of wide input parse in time that grows linearly, timed the way crates/parsec's hostile tests are, and a million-deep member chain writes out on a 256 KB thread. `max_depth`, `max_steps` and `max_input` each stop where they're set. - A `parse` fuzz target: scripts and modules, with the default limits and small ones; every span inside the input and on character boundaries, and every tree written out. In the nightly matrix, seeded with 2,603 test262 files minimized with `cargo fuzz cmin`. - The first run found a panic: a tagged template's cut-short `\u` escape before a character of more than one byte sliced inside it in `text::template_cooked`. Fixed, with a unit test and a fixture case. - DEFAULT_MAX_DEPTH says how much stack a higher limit needs.
This was referenced Nov 21, 2026
Brings the branch onto its new base after the pull request below it merged.
This branch has not been deployed
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.
Fixes #155.
Builds on #188, which this is based on; once that merges, this is rebased onto its base.
Problem. Since #187 the parser counts its depth against
Limits::max_depth(256 by default) and spends a step per token from the budget, but no test showed that hostile input stops there, or that wide input stays linear. Only the lexer had a fuzz target, so nothing threw arbitrary input at the grammar or the ESTree writer.Change.
tests/limits.rs, in the shape ofcrates/parsec-css/tests/limits.rsandcrates/parsec's hostile tests:((((fails withtoo-deepon a 1 MB thread, stopping within the first thousand bytes, so its time doesn't grow with the input.if, loops, labels, functions, classes, arrows, conditionals, assignments, prefix operators,new,**, calls, templates, computed keys, binding and assignment patterns, and arrow parameters.grows_linearlyincrates/parsecdoes. They're chains of operators, members, calls and optional chains, long lists of every kind, 20,000 private names, 20,000 labels, anelse ifchain, aswitchwith 20,000 cases,{a = 1}patterns waiting to be resolved, comments where the parser looks ahead, and wide arrays 50 patterns deep.+chain a million deep (trees built in a loop) write out as ESTree on a 256 KB thread.max_depth,max_stepsandmax_inputeach stop exactly where they're set. A limit above the default runs on a thread sized for it: about 1 KB a level in a release build, 3 KB in a debug one, whichDEFAULT_MAX_DEPTH's doc now says.fuzz/fuzz_targets/parse.rs: any input as a script and as a module, with the default limits and withmax_depth: 8, max_steps: 64. Every node's and comment's span is inside the input and on character boundaries, every error's span is inside the input, and a tree that parsed writes out as ESTree. It joinslexinfuzz.yml's nightly matrix.fuzz/corpus/parse: 2,603 test262 files fromlanguage/andannexB/under 4 KB, with their licence headers and frontmatter stripped (they're noise to a parser) and minimized withcargo fuzz cmin, 750 KB in all. test262'sLICENSEis already beside the corpora.\uescape cut short before a character of more than one byte (tag`\u/0é`) madetext::template_cookedslice inside that character. The four-digit form now reads hex digits only.Tests.
tests/limits.rs: 7 tests, 8 s in a debug build and 1.5 s in a release build.text::tests::template_valuesfails without the fix:`\u/00é`panics with "byte index 4 is not a char boundary".tests/estree/literals.jsgainstag`\u/00é and \u00é`; acorn 8.19.0 agrees that its cooked value isnull.cargo +nightly fuzz run parse -- -max_total_time=300 -max_len=4096, as the nightly job runs it: 3,810,632 runs in 301 seconds, no crash.cargo test --workspace,cargo clippy --workspace --all-targets -- -D warnings,cargo fmt --all --check,cargo docwith-D warnings, the fuzz manifests'cargo metadata, andscripts/check-headers.shpass locally.