mirror of
https://github.com/storytold/gridcraft.git
synced 2026-10-24 10:46:50 -06:00
A hostile file could abort any process that opens it: a cell formula of a million `%` (`1%%%…`) or a 200,000-term sum parsed into trees deep enough to overflow the stack when printed, saved, evaluated or dropped, even in release builds. Postfix operators (`%`, invoking a result) built their nesting in a loop that the 256-level limit did not see. - `parse` refuses formula text longer than Excel's 8,192 characters (`MAX_FORMULA_LEN`, counted in characters, the leading `=` excluded). This also bounds the depth of the left-deep trees long operator chains build. - Each postfix `%` and each call of a result counts towards the nesting limit. - A file's formula that is refused keeps its text and cached value, as other unparsable formulas do. Regression tests: formula (small-stack thread: long `%`, invoke and operator chains are errors; the limit counts characters, not bytes) and xlsx (`hostile_formula_text_does_not_overflow_the_stack`: open, save and drop a workbook with such formulas and a defined name on a 1 MiB stack). Both abort with a stack overflow without the fix. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>