tape: Safely cast when dynamically encoding/decoding
This commit is contained in:
@@ -171,10 +171,12 @@ 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 }
|
||||
oneTag, nn, err := decoder.ReadTag()
|
||||
n += nn; if err != nil { return n, err }
|
||||
if destination.Cap() < int(length) {
|
||||
destination.Grow(int(length) - destination.Cap())
|
||||
if destination.Cap() < lengthCast {
|
||||
destination.Grow(lengthCast - destination.Cap())
|
||||
}
|
||||
// skip the rest of the array if the one tag doesn't
|
||||
// match up with the destination
|
||||
@@ -187,7 +189,7 @@ func decodeAnyOrError(decoder *Decoder, destination reflect.Value, tag Tag) (n i
|
||||
break
|
||||
}
|
||||
if err != nil { return n, err }
|
||||
destination.SetLen(int(length))
|
||||
destination.SetLen(lengthCast)
|
||||
for index := range length {
|
||||
nn, err := decodeAny(decoder, destination.Index(int(index)), oneTag)
|
||||
n += nn
|
||||
|
||||
Reference in New Issue
Block a user