Never crash: reject deeply nested expressions instead of overflowing the stack
An expression nested about 60 brackets deep overflowed the stack of a 2 MiB thread in the JavaScript parser (release and debug; ~200 levels on 8 MiB), which aborts the whole app: it can't be caught. The array-maths rewrite also nests one call per arithmetic operator, so a long sum went the same way, and the rewriter itself recursed per bracket. rewrite() now measures the nesting (brackets plus chains of prefix operators) before and after rewriting and turns an expression deeper than MAX_NESTING (32) into a RangeError; check_syntax reports the same error. Also replaces the unreachable!() in the bracket-tree builder with a let-chain, and denies the panic lints in the crate. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
10644a83aa
commit
fc8fea031c
@@ -24,6 +24,8 @@
|
||||
//! the project through memoized host requests (see [`host`]), so nothing borrowed ever enters
|
||||
//! the JS heap. Expressions reading each other nest up to [`MAX_DEPTH`] levels.
|
||||
|
||||
#![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable)]
|
||||
|
||||
pub mod host;
|
||||
mod noise;
|
||||
pub mod rewrite;
|
||||
@@ -182,6 +184,7 @@ pub fn eval_property(project: &Project, comp: ItemId, layer: LayerId, path: &str
|
||||
|
||||
/// Syntax-check an expression (after the array-maths rewrite) without evaluating it.
|
||||
pub fn check_syntax(text: &str) -> Result<(), String> {
|
||||
rewrite::check_nesting(text)?;
|
||||
runtime::check(text)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user