Skip to content

Commit

Permalink
Merge pull request #354 from TileDB-Inc/phw/prevent-int-overflow
Browse files Browse the repository at this point in the history
Return an error if the buffer is too large.
  • Loading branch information
NullHypothesis authored Oct 10, 2024
2 parents 529198b + d7466d5 commit 9e2c19f
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import "C"
import (
"bytes"
"fmt"
"math"
"runtime"
"unsafe"
)
Expand Down Expand Up @@ -148,6 +149,10 @@ func (b *Buffer) dataCopy() ([]byte, error) {
// Since this buffer is TileDB-managed, make sure it's not GC'd before we're
// done with its memory.
defer runtime.KeepAlive(b)

if csize > math.MaxInt32 {
return nil, fmt.Errorf("TileDB's buffer (%d) larger than maximum allowed CGo buffer (%d)", csize, math.MaxInt32)
}
return C.GoBytes(cbuffer, C.int(csize)), nil
}

Expand Down

0 comments on commit 9e2c19f

Please sign in to comment.