go-yaml / yaml

YAML support for the Go language.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Indefinite recursion in decoder.prepare()

aathan opened this issue · comments

I'm probably unimaginative and can't think of the use-case this is meant to support, but it seems to me that in decode.go:

func (d *decoder) prepare(n *Node, out reflect.Value) (newout reflect.Value, unmarshaled, good bool) {
	if n.ShortTag() == nullTag {
		return out, false, false
	}
	again := true
	for again {
		again = false
		if out.Kind() == reflect.Ptr {
			if out.IsNil() {
				out.Set(reflect.New(out.Type().Elem()))
			}
			out = out.Elem()
			again = true
			continue
		}

... is this really what's desired? Seems to me that this would cause a var foo *(*(*(*int))) to instantiate a ***int then a **int then a *int then an int .... before unmarsahling the scalar. Is that really what we want?

If not, seems like the check of reflect.Ptr() can be hoisted out of the loop, and then there's no need for a loop at all.