Limit binary data to 21MB

This commit is contained in:
Jae Kwon
2015-07-07 18:35:21 -07:00
parent 5734496819
commit 1f34236948
5 changed files with 44 additions and 10 deletions

View File

@ -2,10 +2,16 @@ package binary
import (
"encoding/json"
"errors"
"io"
"reflect"
)
// TODO document and maybe make it configurable.
const MaxBinaryReadSize = 21 * 1024 * 1024
var ErrMaxBinaryReadSizeReached = errors.New("Error: max binary read size reached")
func ReadBinary(o interface{}, r io.Reader, n *int64, err *error) interface{} {
rv, rt := reflect.ValueOf(o), reflect.TypeOf(o)
if rv.Kind() == reflect.Ptr {