alecthomas / alecthomas/participle

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

Aberta
#480 0 comentários 0 reações 0 responsáveis Ver no GitHub
Linguagem predominante
Go
Estrelas
3.9k
Forks
213
Métricas de merge de PRs
Nenhum PR com merge em 30d

Descrição

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.

Guia de contribuição

Nenhum guia de contribuição indexado para este repositório

Avaliação

Esta issue ainda não foi avaliada.

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.