Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/nanoarrow/common/array.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions src/nanoarrow/common/array_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Loading