alecthomas / alecthomas/participle

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

Aperta
#480 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Go
Stelle
3.9k
Fork
213
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.