Skip to content

Add input length cap and parenthesis depth limit to expression parser#13

Merged
andrew merged 1 commit intomainfrom
fix/parse-depth-limit
May 2, 2026
Merged

Add input length cap and parenthesis depth limit to expression parser#13
andrew merged 1 commit intomainfrom
fix/parse-depth-limit

Conversation

@andrew
Copy link
Copy Markdown
Contributor

@andrew andrew commented May 2, 2026

`parseAtom` recurses into `parseExpression` on every `(` with no depth bound, so a sufficiently long run of open parentheses overflows the goroutine stack and fatally crashes the process rather than returning an error. `Valid()` does not protect against this either since it just calls `Parse`.

Adds a `depth` counter to the parser struct, incremented and checked against `maxParseDepth` (256) in the `tokenOpenParen` branch of `parseAtom`. Also adds a 1 MiB input length cap at the top of `Parse` and `ParseStrict`. Both limits return `ErrExpressionTooLarge`.

parseAtom recurses into parseExpression on each open parenthesis with no
depth bound, so a long run of '(' overflows the goroutine stack and
fatally crashes the process. Adds a depth counter on the parser struct
checked on each open paren, and a 1 MiB input length cap at the top of
Parse and ParseStrict. Both return ErrExpressionTooLarge.
@andrew andrew merged commit bec1b07 into main May 2, 2026
2 checks passed
@andrew andrew deleted the fix/parse-depth-limit branch May 2, 2026 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant