alecthomas / alecthomas/participle

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

Offen
#480 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Go
Sterne
3.9k
Forks
213
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

Related to #95.

Parsing deeply nested expressions causes `runtime: goroutine stack exceeds 1000000000-byte limit` / `fatal error: stack overflow`, which kills the process. This is because the parser recurses through `disjunction.Parse -> group.Parse -> capture.Parse -> strct.Parse -> sequence.Parse` with no depth cap.

Reproduction with any recursive grammar:

```go
input := strings.Repeat("(", 300000) + "1" + strings.Repeat(")", 300000)
p.ParseString("", input)
// -> fatal error: stack overflow
```

Stack trace starts with:
```
runtime: goroutine stack exceeds 1000000000-byte limit
fatal error: stack overflow

goroutine 1:
github.com/alecthomas/participle/v2.(*disjunction).Parse (nodes.go:331)
github.com/alecthomas/participle/v2.(*group).Parse (nodes.go:255)
github.com/alecthomas/participle/v2.(*capture).Parse (nodes.go:417)
...repeating
```

Go's stack overflow fatal error is not recoverable with `recover()`, so the whole process dies.

Tested on HEAD `98a9454`. A max-recursion-depth counter that returns a normal error would fix it.

Found by coverage-guided fuzzing.

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.