Compare commits
No commits in common. "44fb561758660647a505348adb252182132fcc79" and "0ea7e222cc0eba0a631f6ff35b71cf39872804a1" have entirely different histories.
44fb561758
...
0ea7e222cc
@ -602,7 +602,7 @@ func (this *Generator) generateDecodeValue(typ Type, typeName, valueSource, tagS
|
|||||||
this.pop()
|
this.pop()
|
||||||
nn, err = this.iprintf("}\n")
|
nn, err = this.iprintf("}\n")
|
||||||
n += nn; if err != nil { return n, err }
|
n += nn; if err != nil { return n, err }
|
||||||
nn, err = this.iprintf("buffer := make([]byte, %s)\n", lengthVar)
|
nn, err = this.iprintf("buffer := make([]byte, int(%s))\n", lengthVar)
|
||||||
n += nn; if err != nil { return n, err }
|
n += nn; if err != nil { return n, err }
|
||||||
nn, err = this.iprintf("nn, err = decoder.Read(buffer)\n")
|
nn, err = this.iprintf("nn, err = decoder.Read(buffer)\n")
|
||||||
n += nn; if err != nil { return n, err }
|
n += nn; if err != nil { return n, err }
|
||||||
@ -799,7 +799,7 @@ func (this *Generator) generateDecodeBranch(hash [16]byte, typ Type, typeName st
|
|||||||
// problems
|
// problems
|
||||||
|
|
||||||
// read fields
|
// read fields
|
||||||
nn, err = this.iprintf("for _ = range %s {\n", lengthVar)
|
nn, err = this.iprintf("for _ = range int(%s) {\n", lengthVar)
|
||||||
n += nn; if err != nil { return n, err }
|
n += nn; if err != nil { return n, err }
|
||||||
this.push()
|
this.push()
|
||||||
// read field header
|
// read field header
|
||||||
|
|||||||
@ -171,12 +171,10 @@ func decodeAnyOrError(decoder *Decoder, destination reflect.Value, tag Tag) (n i
|
|||||||
if length > uint64(MaxStructureLength) {
|
if length > uint64(MaxStructureLength) {
|
||||||
return 0, ErrTooLong
|
return 0, ErrTooLong
|
||||||
}
|
}
|
||||||
lengthCast, err := Uint64ToIntSafe(length)
|
|
||||||
if err != nil { return n, err }
|
|
||||||
oneTag, nn, err := decoder.ReadTag()
|
oneTag, nn, err := decoder.ReadTag()
|
||||||
n += nn; if err != nil { return n, err }
|
n += nn; if err != nil { return n, err }
|
||||||
if destination.Cap() < lengthCast {
|
if destination.Cap() < int(length) {
|
||||||
destination.Grow(lengthCast - destination.Cap())
|
destination.Grow(int(length) - destination.Cap())
|
||||||
}
|
}
|
||||||
// skip the rest of the array if the one tag doesn't
|
// skip the rest of the array if the one tag doesn't
|
||||||
// match up with the destination
|
// match up with the destination
|
||||||
@ -189,7 +187,7 @@ func decodeAnyOrError(decoder *Decoder, destination reflect.Value, tag Tag) (n i
|
|||||||
break
|
break
|
||||||
}
|
}
|
||||||
if err != nil { return n, err }
|
if err != nil { return n, err }
|
||||||
destination.SetLen(lengthCast)
|
destination.SetLen(int(length))
|
||||||
for index := range length {
|
for index := range length {
|
||||||
nn, err := decodeAny(decoder, destination.Index(int(index)), oneTag)
|
nn, err := decodeAny(decoder, destination.Index(int(index)), oneTag)
|
||||||
n += nn
|
n += nn
|
||||||
|
|||||||
@ -2,8 +2,7 @@ package tape
|
|||||||
|
|
||||||
// Error enumerates common errors in this package.
|
// Error enumerates common errors in this package.
|
||||||
type Error string; const (
|
type Error string; const (
|
||||||
ErrTooLong Error = "data structure too long"
|
ErrTooLong Error = "data structure too long"
|
||||||
ErrTooLarge Error = "number too large"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Error implements the error interface.
|
// Error implements the error interface.
|
||||||
|
|||||||
@ -11,16 +11,3 @@ package tape
|
|||||||
// You shouldn't need to change this. If you do, it should only be set once at
|
// You shouldn't need to change this. If you do, it should only be set once at
|
||||||
// the start of the program.
|
// the start of the program.
|
||||||
var MaxStructureLength = 1024 * 1024
|
var MaxStructureLength = 1024 * 1024
|
||||||
|
|
||||||
// MaxInt is the maximum value an int can hold. This varies depending on the
|
|
||||||
// system.
|
|
||||||
const MaxInt int = int(^uint(0) >> 1)
|
|
||||||
|
|
||||||
// Uint64ToIntSafe casts the input to an int if it can be done without overflow,
|
|
||||||
// or returns an error otherwise.
|
|
||||||
func Uint64ToIntSafe(input uint64) (int, error) {
|
|
||||||
if input > uint64(MaxInt) {
|
|
||||||
return 0, ErrTooLarge
|
|
||||||
}
|
|
||||||
return int(input), nil
|
|
||||||
}
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user