hcrosse opened a new issue, #1616:
URL: https://github.com/apache/arrow-go/issues/1616
### Describe the bug, including details regarding any error messages,
version, and platform.
`BinaryView.ValidateFull` and `StringView.ValidateFull` panic on 32 bit
platforms when a view's offset plus length exceeds `MaxInt32`. The same input
returns a bounds error on amd64.
I reproduced this on v18.9.0 and main, with Go 1.26.10 on linux/386,
emulated with `qemu-i386` on linux/amd64.
This builds one view with offset `0x7FFFFFF0`, length 32 and a 32 byte data
buffer:
```go
raw := make([]byte, arrow.ViewHeaderSizeBytes)
binary.LittleEndian.PutUint32(raw[0:4], 32)
copy(raw[4:8], "abcd")
binary.LittleEndian.PutUint32(raw[12:16], 0x7FFFFFF0)
data := array.NewData(arrow.BinaryTypes.BinaryView, 1,
[]*memory.Buffer{nil, memory.NewBufferBytes(raw),
memory.NewBufferBytes(bytes.Repeat([]byte("abcd"), 8))}, nil,
0, 0)
defer data.Release()
arr := array.NewBinaryViewData(data)
defer arr.Release()
fmt.Println(arr.ValidateFull())
```
On linux/386:
```text
panic: runtime error: slice bounds out of range [:-2147483632]
```
On linux/amd64:
```text
arrow/array: view at slot 0 references range 2147483632-2147483664 of buffer
0 but that buffer is only 32 bytes long
```
`StringView` has the same result. Full validation should return the range
error on both platforms.
On 32 bit platforms, the same wrap lets `ListView`, `LargeListView`,
`Struct` and `RunEndEncoded` arrays whose offset plus length exceeds `MaxInt32`
pass validation. It also makes `ValidateFull` panic on view arrays with such an
offset and length. `LargeBinary.Validate` and `LargeString.Validate` narrow
offsets to `int` before comparing them with the data length, so they can accept
offsets past the buffer, and `LargeString.ValidateFull` can then panic.
**Cause**
Bounds checks add in `int`, or widen to `int64` only after adding, so the
sum can wrap before the comparison. For the view above, the end is negative,
passes the buffer length check, and the slice panics:
https://github.com/apache/arrow-go/blob/1cfb8bd743b391747702156d75b2b804ae22cab1/arrow/array/binary.go#L772-L778
The run end check widens after adding, unlike the check above it:
https://github.com/apache/arrow-go/blob/1cfb8bd743b391747702156d75b2b804ae22cab1/arrow/array/encoded.go#L289-L297
### Component(s)
Other
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]