Skip to content

Add depth limiting for nested parentheses in math parser to prevent stack overflow #9275

@coderabbitai

Description

@coderabbitai

Context

The math parser in src/lib/litegraph/src/utils/mathParser.ts uses recursive descent parsing which can cause stack overflow with deeply nested parentheses (verified to crash around depth ~3000).

Requested Enhancement

Add a depth counter to prevent stack overflow from pathological input:

  • Increment counter on each ( encountered
  • Bail out if depth exceeds a reasonable limit (e.g., ~200)
  • Return undefined for expressions that exceed the limit

Background

While unlikely in typical widget input scenarios, adding this safeguard would harden the parser against edge-case inputs.

References

┆Issue is synchronized with this Notion page by Unito

Metadata

Metadata

Labels

enhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions