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 4f4ac82c fix(arrow/array): reject string offsets past the data buffer 
in ValidateFull (#1618)
4f4ac82c is described below

commit 4f4ac82c09173769323d73299713fb27d0f5b67f
Author: Harrison Crosse <[email protected]>
AuthorDate: Wed Nov 18 16:52:06 2026 -0500

    fix(arrow/array): reject string offsets past the data buffer in 
ValidateFull (#1618)
    
    ### Rationale for this change
    
    `String.ValidateFull` and `LargeString.ValidateFull` panic on intermediate 
offsets past the data buffer instead of returning an error.
    
    ### What changes are included in this PR?
    
    Both methods now compare each offset with the data length after the 
monotonicity check and before slicing for UTF8 validation. The errors use the 
same wording as `Validate`, plus the index of the bad offset. `Validate` is 
unchanged.
    
    ### Are these changes tested?
    
    Yes. I added tests for intermediate offsets past the buffer in ordinary and 
sliced string arrays.
    
    ### Are there any user-facing changes?
    
    Yes. Full validation returns errors for string offsets past the data buffer 
instead of panicking. There is no API change.
    
    Closes #1615.
---
 arrow/array/string.go        | 14 ++++++++++++--
 arrow/array/validate_test.go | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 44 insertions(+), 2 deletions(-)

diff --git a/arrow/array/string.go b/arrow/array/string.go
index 5e432775..4f31993f 100644
--- a/arrow/array/string.go
+++ b/arrow/array/string.go
@@ -212,7 +212,8 @@ func (a *String) Validate() error {
 
 // ValidateFull performs a full O(n) consistency check on the array data.
 // In addition to the checks performed by Validate, it also verifies that
-// all offsets are non-negative and monotonically non-decreasing.
+// all offsets are non-negative, monotonically non-decreasing, and within the
+// data buffer.
 func (a *String) ValidateFull() error {
        if err := a.Validate(); err != nil {
                return err
@@ -229,6 +230,10 @@ func (a *String) ValidateFull() error {
                        return fmt.Errorf("arrow/array: string offsets are not 
monotonically non-decreasing at index %d: %d < %d",
                                a.data.offset+i, offsets[i], offsets[i-1])
                }
+               if int(offsets[i]) > len(a.values) {
+                       return fmt.Errorf("arrow/array: string offset %d at 
index %d out of bounds of data buffer (length %d)",
+                               offsets[i], a.data.offset+i, len(a.values))
+               }
                value := a.values[offsets[i-1]:offsets[i]]
                if !utf8.ValidString(value) {
                        return fmt.Errorf("arrow/array: string at index %d is 
not valid utf8: %s", a.data.offset+i-1, value)
@@ -430,7 +435,8 @@ func (a *LargeString) Validate() error {
 
 // ValidateFull performs a full O(n) consistency check on the array data.
 // In addition to the checks performed by Validate, it also verifies that
-// all offsets are non-negative and monotonically non-decreasing.
+// all offsets are non-negative, monotonically non-decreasing, and within the
+// data buffer.
 func (a *LargeString) ValidateFull() error {
        if err := a.Validate(); err != nil {
                return err
@@ -447,6 +453,10 @@ func (a *LargeString) ValidateFull() error {
                        return fmt.Errorf("arrow/array: large string offsets 
are not monotonically non-decreasing at index %d: %d < %d",
                                a.data.offset+i, offsets[i], offsets[i-1])
                }
+               if offsets[i] > int64(len(a.values)) {
+                       return fmt.Errorf("arrow/array: large string offset %d 
at index %d out of bounds of data buffer (length %d)",
+                               offsets[i], a.data.offset+i, len(a.values))
+               }
                value := a.values[offsets[i-1]:offsets[i]]
                if !utf8.ValidString(value) {
                        return fmt.Errorf("arrow/array: string at index %d is 
not valid utf8: %s", a.data.offset+i-1, value)
diff --git a/arrow/array/validate_test.go b/arrow/array/validate_test.go
index ac641787..64212d0b 100644
--- a/arrow/array/validate_test.go
+++ b/arrow/array/validate_test.go
@@ -205,6 +205,22 @@ func TestStringValidate(t *testing.T) {
                assert.Contains(t, err.Error(), "not monotonically 
non-decreasing")
        })
 
+       t.Run("intermediate offset past the data buffer passes Validate but 
fails ValidateFull", func(t *testing.T) {
+               arr := makeStringArrayRaw(t, []int32{0, 100, 5}, "hello", 2, 0)
+               assert.NoError(t, arr.Validate())
+               var err error
+               require.NotPanics(t, func() { err = arr.ValidateFull() })
+               assert.EqualError(t, err, "arrow/array: string offset 100 at 
index 1 out of bounds of data buffer (length 5)")
+       })
+
+       t.Run("sliced array offset past the data buffer passes Validate but 
fails ValidateFull", func(t *testing.T) {
+               arr := makeStringArrayRaw(t, []int32{0, 3, 100, 5}, "hello", 2, 
1)
+               assert.NoError(t, arr.Validate())
+               var err error
+               require.NotPanics(t, func() { err = arr.ValidateFull() })
+               assert.EqualError(t, err, "arrow/array: string offset 100 at 
index 2 out of bounds of data buffer (length 5)")
+       })
+
        t.Run("negative first offset passes Validate but fails ValidateFull", 
func(t *testing.T) {
                arr := makeStringArrayRaw(t, []int32{-1, 2, 5}, "hello", 2, 0)
                assert.NoError(t, arr.Validate())
@@ -229,6 +245,22 @@ func TestLargeStringValidate(t *testing.T) {
                assert.Contains(t, err.Error(), "not monotonically 
non-decreasing")
        })
 
+       t.Run("intermediate offset past the data buffer passes Validate but 
fails ValidateFull", func(t *testing.T) {
+               arr := makeLargeStringArrayRaw(t, []int64{0, 100, 5}, "hello", 
2, 0)
+               assert.NoError(t, arr.Validate())
+               var err error
+               require.NotPanics(t, func() { err = arr.ValidateFull() })
+               assert.EqualError(t, err, "arrow/array: large string offset 100 
at index 1 out of bounds of data buffer (length 5)")
+       })
+
+       t.Run("sliced array offset past the data buffer passes Validate but 
fails ValidateFull", func(t *testing.T) {
+               arr := makeLargeStringArrayRaw(t, []int64{0, 3, 100, 5}, 
"hello", 2, 1)
+               assert.NoError(t, arr.Validate())
+               var err error
+               require.NotPanics(t, func() { err = arr.ValidateFull() })
+               assert.EqualError(t, err, "arrow/array: large string offset 100 
at index 2 out of bounds of data buffer (length 5)")
+       })
+
        t.Run("negative first offset passes Validate but fails ValidateFull", 
func(t *testing.T) {
                arr := makeLargeStringArrayRaw(t, []int64{-1, 2, 5}, "hello", 
2, 0)
                assert.NoError(t, arr.Validate())

Reply via email to