Repository navigation
fuzz_regexp: size the capture array for lre_exec() and add a real stack check - #570
Open
JasonGross wants to merge 1 commit into
Open
JasonGross wants to merge 1 commit into
JasonGross wants to merge 1 commit into
Conversation
lre_exec() keeps the quantifier registers after the capture slots, so the array it is given must hold lre_get_alloc_count() entries: up to 2 * 255 captures plus 255 nested quantifier registers. The harness passed a 255 * 2 array, so 254 capture groups followed by a counted quantifier wrote past its end. Make it 255 * 3. lre_check_stack_overflow() was a stub returning 0, so deeply nested patterns overflowed the C stack. Check the stack pointer against a limit 1 MiB below where LLVMFuzzerTestOneInput() started, as quickjs.c does. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
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.
Two problems in
fuzz/fuzz_regexp.c, the libFuzzer target for libregexp:The capture array is too small. The harness passes
uint8_t *capture[255 * 2]tolre_exec().Since the change that added
lre_get_alloc_count(),lre_exec()also keeps the quantifier registersin that array after the capture slots, so it needs up to
2 * 255 + 255entries. A pattern with 254capture groups followed by a counted quantifier makes
lre_exec()write past the end of the stackarray. For example, the input
()repeated 254 times, thena{2}, a NUL byte andaacompiles to255 captures plus one quantifier register: 511 slots for a 510-entry array. Each further level of
nested quantifier adds one more slot, up to the parser's limit of 255 levels (765 slots). The fix
makes the array
255 * 3entries.The stack check is a stub.
lre_check_stack_overflow()always returns 0, so the recursive parserhas no depth limit, and a deeply nested pattern overflows the C stack. For example, 100,000 nested
non-capturing groups (
(?:...a...)) crash the current harness with SIGSEGV on an 8 MiB stack.The fix does the same check as
js_check_stack_overflow()in quickjs.c: it records a limit of1 MiB below the stack pointer when
LLVMFuzzerTestOneInput()starts and compares against it. Deeppatterns then fail with the parser's normal "stack overflow" error.
Only the fuzz target changes.
🤖 Written with Claude Code (Claude Opus 5.5)