alecthomas / alecthomas/participle

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

Abierto
#480 0 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Go
Estrellas
3.9k
Forks
213
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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.

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Evaluación

Este issue todavía no se ha evaluado.

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.