diff --git a/batch_command.go b/batch_command.go index 93732450..1506245b 100644 --- a/batch_command.go +++ b/batch_command.go @@ -22,10 +22,6 @@ import ( Buffer "github.com/aerospike/aerospike-client-go/utils/buffer" ) -const ( - _MAX_BUFFER_SIZE = 1024 * 1024 * 10 // 10 MB -) - type multiCommand interface { Stop() } @@ -114,7 +110,7 @@ func (cmd *baseMultiCommand) readBytes(length int) error { if length > len(cmd.dataBuffer) { // Corrupted data streams can result in a huge length. // Do a sanity check here. - if length > _MAX_BUFFER_SIZE { + if length > MaxBufferSize { return NewAerospikeError(PARSE_ERROR, fmt.Sprintf("Invalid readBytes length: %d", length)) } cmd.dataBuffer = make([]byte, length) diff --git a/command.go b/command.go index bf062606..ddff9ece 100644 --- a/command.go +++ b/command.go @@ -875,10 +875,17 @@ func (cmd *baseCommand) sizeBuffer() error { return cmd.sizeBufferSz(cmd.dataOffset) } +var ( + // MaxBufferSize protects against allocating massive memory blocks + // for buffers. Tweak this number if you are returning a lot of + // LDT elements in your queries. + MaxBufferSize = 1024 * 1024 * 10 // 10 MB +) + func (cmd *baseCommand) sizeBufferSz(size int) error { // Corrupted data streams can result in a huge length. // Do a sanity check here. - if size > _MAX_BUFFER_SIZE { + if size > MaxBufferSize { return NewAerospikeError(PARSE_ERROR, fmt.Sprintf("Invalid size for buffer: %d", size)) }