Repository navigation
Formula parser: Excel's 8,192-character limit and postfix nesting (never crash) - #1330
Merged
skylartaylor merged 1 commit intoOct 15, 2026
Conversation
…ver crash) 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>
Member
|
Thanks @nihilist-narwhal! Nice targeted fix with good hostile-input coverage. Merged. Thanks also @PierrunoYT and @midasmatterhorn for the reports and follow-up audit. The broader AST/accounting-number recursion cases in #1001 still need separate work. |
This was referenced Oct 17, 2026
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.
What this changes
A hostile file could abort any process that opens it, GridCraft included: a cell formula of about a million
%(=1%%%…) or a 200,000-term sum (=1+1+…) 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.parserefuses 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.%and each call of a result now counts towards the nesting limit.Part of #1307 (finding 1). Covers the binary, postfix and invocation chains from #1001; the recursive stripping of accounting parentheses in
parse_numeric, also listed there, is not changed here.Tests
formula:hostile_formulas_are_errors_not_stack_overflows(small-stack thread: long%, invoke and operator chains are errors) andformulas_longer_than_excel_allows_are_refused(the limit counts characters, not bytes).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.cargo fmt --all --check,cargo clippy --workspace --all-targets -- -D warnings,cargo test --workspace, andcargo xtaskassets / layers /parity --check/keytips --checkpass.cargo xtask ci(fmt, clippy, test, assets, layers, wasm, parity, keytips) passes in CI.