go-yaml
go-yaml copied to clipboard
Recursive anchor causes stack overflow
The following yaml causes a stack overflow:
key1: &anchor
subkey: *anchor
key2: *anchor
If you remove either the second or third line, it parses successfully. Here's a real-world example where this fails.
Here's a minimal example:
package main
import (
"github.com/goccy/go-yaml"
)
type Key struct {
SubKey *Key `yaml:"subkey"`
}
type Test struct {
Key1 *Key `yaml:"key1"`
Key2 *Key `yaml:"key2"`
}
var test = []byte(`
key1: &anchor
subkey: *anchor
key2: *anchor
`)
func main() {
t := new(Test)
// causes stack overflow
yaml.Unmarshal(test, t)
}