mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
5bb4a15086
The backtracking engine recurses via C function calls at RE_SPLIT, RE_SPLITNG, RE_SAVE, RE_LOOKAHEAD, RE_NEG_LOOKAHEAD, RE_LOOKBEHIND, and RE_NEG_LOOKBEHIND. Patterns like `(?=)+` make the engine recurse without consuming input, exhausting the C stack and triggering SIGSEGV long before MRB_REGEXP_STEP_LIMIT is reached (each recursion charges only ~1 step, but each frame costs ~150 bytes of stack). Reported by ClusterFuzz testcase clusterfuzz-testcase-minimized-mruby_fuzzer-4653331195953152. Add an integer recursion-depth counter passed alongside the step counter, and abort the current branch with FALSE when it exceeds MRB_REGEXP_RECURSION_LIMIT (default 1000, configurable like STEP_LIMIT). Legitimate patterns nest only a few levels; pathological inputs bail without crashing the VM. Co-authored-by: Claude <noreply@anthropic.com>