go-yaml icon indicating copy to clipboard operation
go-yaml copied to clipboard

Recursive anchor causes stack overflow

Open korylprince opened this issue 1 year ago • 0 comments

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)
}

korylprince avatar Mar 06 '23 16:03 korylprince