Skip to content

parser: cap recursive production depth - #485

Open
team-humaki wants to merge 1 commit into
alecthomas:masterfrom
team-humaki:parse-depth-limit
Open

team-humaki wants to merge 1 commit into
alecthomas:masterfrom
team-humaki:parse-depth-limit

Conversation

@team-humaki

Copy link
Copy Markdown

Fixes #480.

Deeply nested input (for example 300k nested parentheses) recurses through strct.Parse until the goroutine stack overflows. That fatal error is not recoverable with recover(), so the process dies.

Count nested productions on parseContext and return a ParseError once MaxParseDepth (default 1024, 0 disables) is exceeded. Shallow input is unchanged.

go test . green (TestMaxParseDepth).

Deeply nested input overflowed the goroutine stack because
strct.Parse had no nesting bound. Count productions and return
a ParseError once MaxParseDepth is exceeded.
Comment thread nodes.go
// MaxParseDepth limits recursive production nesting. Deeply nested input
// otherwise overflows the goroutine stack with a fatal error that recover
// cannot catch. Zero disables the limit.
MaxParseDepth = 1024

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this should be configurable through a parser option.

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.

Parser stack overflow on deeply nested input (no recursion depth limit)

2 participants