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

paleolimbot pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-nanoarrow.git


The following commit(s) were added to refs/heads/main by this push:
     new 85517e37 fix: Bound large list view elements without overflowing 
int64_t (#1005)
85517e37 is described below

commit 85517e3723998acf1ac6af31aa869cceb00e8963
Author: Pedro Z <[email protected]>
AuthorDate: Thu Nov 5 18:13:20 2026 +0100

    fix: Bound large list view elements without overflowing int64_t (#1005)
    
    `ArrowArrayViewValidateFull()` bounds each list view and large list view
    element as `offset + size > child_len`. Both values have already been
    checked to be non-negative, but for a large list view two large values
    overflow the `int64_t` sum, which is undefined behaviour. In practice
    the sum wraps to a negative number, so an element that points far past
    the child passes full validation. UBSan reports it as `signed integer
    overflow: 9223372036854775807 + 9223372036854775807 cannot be
    represented in type 'int64_t'`. The check is now `size > child_len -
    offset`, which cannot overflow once both are non-negative. The error
    message is unchanged.
    
    `ArrayViewTestLargeListView` now also validates an element with offset
    and size both `INT64_MAX` against a child of length 1. It expects
    `EINVAL` and the usual message. Without the fix, full validation returns
    `NANOARROW_OK` and the test fails, and under UBSan it stops at the
    addition.
    
    The input was found by fuzzing the IPC reader in the
    [zuarrow](https://github.com/pedrobtz/zuarrow) R package, which vendors
    nanoarrow.
    
    `ctest` passes in a plain build and with ASan and UBSan (410 tests). The
    changed files are formatted with the pinned clang-format 16.0.6.
    
    🤖 Generated with [Claude Code](https://claude.com/claude-code)
    
    Co-authored-by: Claude Opus 5.5 <[email protected]>
---
 src/nanoarrow/common/array.c       |  3 ++-
 src/nanoarrow/common/array_test.cc | 10 ++++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/src/nanoarrow/common/array.c b/src/nanoarrow/common/array.c
index ee308ea6..3cafbb6f 100644
--- a/src/nanoarrow/common/array.c
+++ b/src/nanoarrow/common/array.c
@@ -2252,7 +2252,8 @@ static int ArrowArrayViewValidateFull(struct 
ArrowArrayView* array_view,
         return EINVAL;
       }
 
-      if ((offset + size) > child_len) {
+      // offset and size are non-negative here, so this cannot overflow like 
their sum
+      if (size > child_len - offset) {
         ArrowErrorSet(error,
                       "Offset: %" PRId64 " + size: %" PRId64 " at index: %" 
PRId64
                       " exceeds length of child view: %" PRId64,
diff --git a/src/nanoarrow/common/array_test.cc 
b/src/nanoarrow/common/array_test.cc
index 31f44270..c1508f92 100644
--- a/src/nanoarrow/common/array_test.cc
+++ b/src/nanoarrow/common/array_test.cc
@@ -3847,6 +3847,16 @@ TEST(ArrayTest, ArrayViewTestLargeListView) {
             EINVAL);
   EXPECT_STREQ(error.message,
                "Offset: 1 + size: 42 at index: 1 exceeds length of child view: 
1");
+
+  // An offset and a size whose sum overflows int64_t must still be out of 
bounds
+  offsets[1] = INT64_MAX;
+  sizes[1] = INT64_MAX;
+  EXPECT_EQ(ArrowArrayViewSetArray(&array_view, &array, &error), NANOARROW_OK);
+  EXPECT_EQ(ArrowArrayViewValidate(&array_view, 
NANOARROW_VALIDATION_LEVEL_FULL, &error),
+            EINVAL);
+  EXPECT_STREQ(error.message,
+               "Offset: 9223372036854775807 + size: 9223372036854775807 at 
index: 1 "
+               "exceeds length of child view: 1");
   ArrowArrayRelease(&array);
   ArrowArrayViewReset(&array_view);
 }

Reply via email to