diff --git a/tape/dynamic.go b/tape/dynamic.go index 120eb50..31966b6 100644 --- a/tape/dynamic.go +++ b/tape/dynamic.go @@ -240,8 +240,16 @@ func decodeAnyOrError(decoder *Decoder, destination reflect.Value, tag Tag) (n i if length > uint64(MaxStructureLength) { return 0, ErrTooLong } + lengthCast, err := Uint64ToIntSafe(length) + if err != nil { return n, err } + if isTypeAny(destination.Type()) { + // need a skeleton value if we are assigning to any. + value := reflect.MakeMapWithSize(reflect.TypeOf(dummyMap), lengthCast) + destination.Set(value) + destination = value + } destination.Clear() - for _ = range length { + for _ = range lengthCast { key, nn, err := decoder.ReadUint16() n += nn; if err != nil { return n, err } itemTag, nn, err := decoder.ReadTag()