You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by we...@apache.org on 2019/08/09 01:26:31 UTC

[arrow] branch master updated: ARROW-6166: [Go] Fix index out of bounds panic when slicing a slice

This is an automated email from the ASF dual-hosted git repository.

wesm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow.git


The following commit(s) were added to refs/heads/master by this push:
     new 698a88e  ARROW-6166: [Go] Fix index out of bounds panic when slicing a slice
698a88e is described below

commit 698a88e5e3633fe4dc73ab69aedb4b13f143d225
Author: roshie548 <ro...@gmail.com>
AuthorDate: Thu Aug 8 20:26:19 2019 -0500

    ARROW-6166: [Go] Fix index out of bounds panic when slicing a slice
    
    Fixes #5033
    
    Closes #5035 from roshie548/master and squashes the following commits:
    
    585b25133 <roshie548>  Fix index out of bounds panic when slicing a slice of length 1
    
    Authored-by: roshie548 <ro...@gmail.com>
    Signed-off-by: Wes McKinney <we...@apache.org>
---
 go/arrow/array/array_test.go | 12 +++++++++++-
 go/arrow/array/data.go       |  2 +-
 2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/go/arrow/array/array_test.go b/go/arrow/array/array_test.go
index 590fa3c..af50cf9 100644
--- a/go/arrow/array/array_test.go
+++ b/go/arrow/array/array_test.go
@@ -286,6 +286,16 @@ func TestArraySliceTypes(t *testing.T) {
 			if got, want := slice.Len(), 3; got != want {
 				t.Fatalf("invalid slice length: got=%d, want=%d", got, want)
 			}
+
+			shortSlice := array.NewSlice(arr, 2, 3)
+			defer shortSlice.Release()
+
+			sliceOfShortSlice := array.NewSlice(shortSlice, 0, 1)
+			defer sliceOfShortSlice.Release()
+
+			if got, want := sliceOfShortSlice.Len(), 1; got != want {
+				t.Fatalf("invalid short slice length: got=%d, want=%d", got, want)
+			}
 		})
 	}
-}
+}
\ No newline at end of file
diff --git a/go/arrow/array/data.go b/go/arrow/array/data.go
index 58b1648..e7a69e9 100644
--- a/go/arrow/array/data.go
+++ b/go/arrow/array/data.go
@@ -99,7 +99,7 @@ func (d *Data) Buffers() []*memory.Buffer { return d.buffers }
 // NewSliceData panics if the slice is outside the valid range of the input Data.
 // NewSliceData panics if j < i.
 func NewSliceData(data *Data, i, j int64) *Data {
-	if j > int64(data.length) || i > j || data.offset+int(i) > data.length {
+	if j > int64(data.length) || i > j || data.offset+int(i) > data.offset+data.length {
 		panic("arrow/array: index out of range")
 	}