From ccf0d8c95c212f0481150f6d21fa6ea2f96cf789 Mon Sep 17 00:00:00 2001 From: pedrobtz Date: Thu, 5 Nov 2026 16:25:35 +0100 Subject: [PATCH] fix: Bound large list view elements without overflowing int64_t ArrowArrayViewValidateFull() checked a large list view element as offset + size > child_len. Two large non-negative values overflow that sum, so a wrapped result passed the check. Compare size against child_len - offset instead, which cannot overflow once both are known to be non-negative. Co-Authored-By: Claude Opus 5.5 --- 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 ee308ea61..3cafbb6f5 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 31f442708..c1508f929 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); }