Skip to content

Commit

Permalink
Return an error if the buffer is too large.
Browse files Browse the repository at this point in the history
So far, we would case a uint64 to a int32 but that may result in an
integer overflow. At this point, GoBytes does not seem to support
buffers this large, so the next best thing to do is return an error if
the given buffer is too large.
  • Loading branch information
NullHypothesis committed Oct 9, 2024
1 parent 529198b commit cc06241
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 cc06241

Please sign in to comment.