mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-02 22:41:47 -06:00
boa's parser and compiler recurse once per nesting level and have no limit of their own: about 100 nested parentheses in a field or document script overflowed a 2 MiB stack and aborted the app, which `catch_unwind` can't stop. `printcraft_js::run` now: - refuses a script longer than 256 KiB, or one that nests brackets more than 64 deep, chains more than 64 prefix operators, or has more than 4096 `?`. Strings and comments are skipped. The script fails with an error, as a syntax error would; - runs the engine on its own thread with a 1 GiB stack, which is address space, committed only as it's used. That covers every unbracketed construct a 256 KiB script can nest. A panic inside the engine becomes a script error. On wasm the script still runs inline. Regression tests: `deeply_nested_scripts_fail_instead_of_crashing`, which aborted the test process before this change, and `ordinary_nesting_still_runs`. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>