mirror of
https://github.com/storytold/gridcraft.git
synced 2026-10-25 11:16:49 -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>
20 lines
707 B
Rust
20 lines
707 B
Rust
//! The Excel formula language: tokenizer, parser, syntax tree, printer (A1 and R1C1) and
|
|
//! reference adjustment for copy/fill and structural edits.
|
|
#![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable)]
|
|
#![forbid(unsafe_code)]
|
|
|
|
pub mod adjust;
|
|
pub mod ast;
|
|
mod input;
|
|
pub mod lexer;
|
|
pub mod parser;
|
|
pub mod printer;
|
|
|
|
pub use ast::{Anchor, BinOp, Expr, RefKind, Reference, SheetSel, StructItem, StructRef, TrimMode, UnOp};
|
|
pub use input::{FormulaLocale, parse_input, print_input};
|
|
pub use parser::{MAX_FORMULA_LEN, ParseError, normalize_function_name, parse};
|
|
pub use printer::{print, print_r1c1, quote_sheet};
|
|
|
|
#[cfg(test)]
|
|
mod tests;
|