This is an automated email from the ASF dual-hosted git repository.
zeroshade pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-go.git
The following commit(s) were added to refs/heads/main by this push:
new 2a130a42 fix(array): validate negative bounds in NewSliceData (#870)
2a130a42 is described below
commit 2a130a425f65f904319c8c3e323596c08f6477ad
Author: Minh Vu <[email protected]>
AuthorDate: Wed Jul 1 00:44:07 2026 +0200
fix(array): validate negative bounds in NewSliceData (#870)
### What changed
NewSliceData now rejects negative start and end bounds before
constructing sliced Data metadata.
### Why
The existing bounds check rejected end positions past the array length
and start positions after the end, but it did not reject negative
bounds. A call such as NewSliceData(data, -1, 0) could produce a Data
value with a negative offset even though the function documents that
out-of-range slices panic.
### Validation
- go test ./arrow/array -run TestNewSliceDataInvalidBounds -count=1
- go test ./arrow/array -count=1
-
PARQUET_TEST_DATA=/Users/hoangvu/Code/OSS/arrow-go/parquet-testing/data
ARROW_TEST_DATA=/Users/hoangvu/Code/OSS/arrow-go/arrow-testing/data go
test ./... -count=1
---
arrow/array/data.go | 2 +-
arrow/array/data_test.go | 23 +++++++++++++++++++++++
2 files changed, 24 insertions(+), 1 deletion(-)
diff --git a/arrow/array/data.go b/arrow/array/data.go
index 0f017032..eaed4717 100644
--- a/arrow/array/data.go
+++ b/arrow/array/data.go
@@ -229,7 +229,7 @@ func (d *Data) SizeInBytes() uint64 {
// NewSliceData panics if the slice is outside the valid range of the input
Data.
// NewSliceData panics if j < i.
func NewSliceData(data arrow.ArrayData, i, j int64) arrow.ArrayData {
- if j > int64(data.Len()) || i > j || data.Offset()+int(i) >
data.Offset()+data.Len() {
+ if i < 0 || j < 0 || j > int64(data.Len()) || i > j ||
data.Offset()+int(i) > data.Offset()+data.Len() {
panic("arrow/array: index out of range")
}
diff --git a/arrow/array/data_test.go b/arrow/array/data_test.go
index 0a08c787..435d8b69 100644
--- a/arrow/array/data_test.go
+++ b/arrow/array/data_test.go
@@ -51,6 +51,29 @@ func TestDataReset(t *testing.T) {
}
}
+func TestNewSliceDataInvalidBounds(t *testing.T) {
+ data := NewData(&arrow.Int64Type{}, 3, nil, nil, 0, 0)
+ defer data.Release()
+
+ tests := []struct {
+ name string
+ i, j int64
+ }{
+ {name: "negative start", i: -1, j: 0},
+ {name: "negative end", i: -2, j: -1},
+ {name: "end beyond length", i: 0, j: 4},
+ {name: "start after end", i: 2, j: 1},
+ }
+
+ for _, tt := range tests {
+ t.Run(tt.name, func(t *testing.T) {
+ assert.PanicsWithValue(t, "arrow/array: index out of
range", func() {
+ NewSliceData(data, tt.i, tt.j)
+ })
+ })
+ }
+}
+
func TestSizeInBytes(t *testing.T) {
var buffers1 = make([]*memory.Buffer, 0, 3)