Fix bug in merkle/iavl_proof; TODO maybe read zero length slices as nil?

This commit is contained in:
Jae Kwon
2015-07-08 18:27:16 -07:00
parent ff6aa089ea
commit d95234435a
9 changed files with 33 additions and 13 deletions
+2 -1
View File
@@ -10,7 +10,8 @@ import (
// TODO document and maybe make it configurable.
const MaxBinaryReadSize = 21 * 1024 * 1024
var ErrMaxBinaryReadSizeReached = errors.New("Error: max binary read size reached")
var ErrBinaryReadSizeOverflow = errors.New("Error: binary read size overflow")
var ErrBinaryReadSizeUnderflow = errors.New("Error: binary read size underflow")
func ReadBinary(o interface{}, r io.Reader, n *int64, err *error) interface{} {
rv, rt := reflect.ValueOf(o), reflect.TypeOf(o)
+14 -4
View File
@@ -2,6 +2,8 @@ package binary
import (
"io"
. "github.com/tendermint/tendermint/common"
)
func WriteByteSlice(bz []byte, w io.Writer, n *int64, err *error) {
@@ -14,8 +16,12 @@ func ReadByteSlice(r io.Reader, n *int64, err *error) []byte {
if *err != nil {
return nil
}
if MaxBinaryReadSize < *n+int64(length) {
*err = ErrMaxBinaryReadSizeReached
if length < 0 {
*err = ErrBinaryReadSizeUnderflow
return nil
}
if MaxBinaryReadSize < MaxInt64(int64(length), *n+int64(length)) {
*err = ErrBinaryReadSizeOverflow
return nil
}
@@ -41,8 +47,12 @@ func ReadByteSlices(r io.Reader, n *int64, err *error) [][]byte {
if *err != nil {
return nil
}
if MaxBinaryReadSize < *n+int64(length) {
*err = ErrMaxBinaryReadSizeReached
if length < 0 {
*err = ErrBinaryReadSizeUnderflow
return nil
}
if MaxBinaryReadSize < MaxInt64(int64(length), *n+int64(length)) {
*err = ErrBinaryReadSizeOverflow
return nil
}
+1 -1
View File
@@ -274,7 +274,7 @@ func readReflectBinary(rv reflect.Value, rt reflect.Type, opts Options, r io.Rea
return
}
if MaxBinaryReadSize < *n {
*err = ErrMaxBinaryReadSizeReached
*err = ErrBinaryReadSizeOverflow
return
}
}
+1 -1
View File
@@ -456,7 +456,7 @@ func TestJSONFieldNames(t *testing.T) {
func TestBadAlloc(t *testing.T) {
n, err := new(int64), new(error)
instance := new([]byte)
data := RandBytes(ByteSliceChunk * 100)
data := RandBytes(100 * 1024)
b := new(bytes.Buffer)
// this slice of data claims to be much bigger than it really is
WriteUvarint(uint(10000000000000000), b, n, err)
+11 -3
View File
@@ -1,6 +1,10 @@
package binary
import "io"
import (
"io"
. "github.com/tendermint/tendermint/common"
)
// String
@@ -14,8 +18,12 @@ func ReadString(r io.Reader, n *int64, err *error) string {
if *err != nil {
return ""
}
if MaxBinaryReadSize < *n+int64(length) {
*err = ErrMaxBinaryReadSizeReached
if length < 0 {
*err = ErrBinaryReadSizeUnderflow
return ""
}
if MaxBinaryReadSize < MaxInt64(int64(length), *n+int64(length)) {
*err = ErrBinaryReadSizeOverflow
return ""
}