Skip to content

Commit

Permalink
test large string
Browse files Browse the repository at this point in the history
  • Loading branch information
paleolimbot committed Sep 19, 2024
1 parent 09645c5 commit f6a2b36
Showing 1 changed file with 32 additions and 4 deletions.
36 changes: 32 additions & 4 deletions src/nanoarrow/common/array_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2256,6 +2256,10 @@ TEST(ArrayTest, ArrayViewTestLargeString) {
EXPECT_EQ(array_view.buffer_views[1].size_bytes, 0);
EXPECT_EQ(array_view.buffer_views[2].size_bytes, 0);

// This should pass validation even if all buffers are empty
ASSERT_EQ(ArrowArrayViewValidate(&array_view, NANOARROW_VALIDATION_LEVEL_FULL, &error),
NANOARROW_OK);

ArrowArrayViewSetLength(&array_view, 5);
EXPECT_EQ(array_view.buffer_views[0].size_bytes, 1);
EXPECT_EQ(array_view.buffer_views[1].size_bytes, (5 + 1) * sizeof(int64_t));
Expand Down Expand Up @@ -2304,17 +2308,41 @@ TEST(ArrayTest, ArrayViewTestLargeString) {
int64_t* offsets =
const_cast<int64_t*>(reinterpret_cast<const int64_t*>(array.buffers[1]));

offsets[0] = -1;
EXPECT_EQ(ArrowArrayViewSetArray(&array_view, &array, &error), EINVAL);
EXPECT_STREQ(error.message, "Expected first offset >= 0 but found -1");
offsets[0] = 0;
// For a sliced array, this can still pass validation
array.offset = 1;
array.length = array_view.length - 1;
EXPECT_EQ(ArrowArrayViewSetArray(&array_view, &array, &error), NANOARROW_OK);
EXPECT_EQ(ArrowArrayViewValidate(&array_view, NANOARROW_VALIDATION_LEVEL_FULL, &error),
NANOARROW_OK);

// Check for negative element sizes
array.offset = 0;
array.length = array.length + 1;
offsets[0] = 0;
offsets[1] = -1;
EXPECT_EQ(ArrowArrayViewSetArray(&array_view, &array, &error), NANOARROW_OK);
EXPECT_EQ(ArrowArrayViewValidate(&array_view, NANOARROW_VALIDATION_LEVEL_FULL, &error),
EINVAL);
EXPECT_STREQ(error.message, "[1] Expected element size >= 0");

// Sliced array should also fail validation because the first element is negative
array.offset = 0;
array.length = array_view.length + 1;
EXPECT_EQ(ArrowArrayViewSetArray(&array_view, &array, &error), NANOARROW_OK);
EXPECT_EQ(ArrowArrayViewValidate(&array_view, NANOARROW_VALIDATION_LEVEL_FULL, &error),
EINVAL);
EXPECT_STREQ(error.message, "[1] Expected element size >= 0");

// Check sequential offsets whose diff causes overflow
array.offset = 0;
array.length = array.length + 1;
offsets[1] = 2080374784;
offsets[2] = INT_MIN;
EXPECT_EQ(ArrowArrayViewSetArray(&array_view, &array, &error), NANOARROW_OK);
EXPECT_EQ(ArrowArrayViewValidate(&array_view, NANOARROW_VALIDATION_LEVEL_FULL, &error),
EINVAL);
EXPECT_STREQ(error.message, "[2] Expected element size >= 0");

ArrowArrayRelease(&array);
ArrowArrayViewReset(&array_view);
}
Expand Down

0 comments on commit f6a2b36

Please sign in to comment.