Skip to content
Closed
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
8 changes: 8 additions & 0 deletions cpp/src/arrow/array/array_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,14 @@ TEST_F(TestArray, ValidateBuffersPrimitive) {
data = ArrayData::Make(int64(), 2, {null_buffer, data_buffer}, kUnknownNullCount, 1);
array = MakeArray(data);
ASSERT_RAISES(Invalid, array->Validate());

// Negative offset. The buffer-size checks use length + offset, so a negative
// offset that cancels the length would otherwise accept too-small buffers and
// leave reads of Value(i) addressing before the buffer.
data = ArrayData::Make(int64(), 2, {null_buffer, data_buffer}, kUnknownNullCount, -2);
array = MakeArray(data);
ASSERT_RAISES(Invalid, array->Validate());
ASSERT_RAISES(Invalid, array->ValidateFull());
}

// ----------------------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions cpp/src/arrow/array/validate.cc
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,10 @@ struct ValidateArrayImpl {
return Status::Invalid("Array length is negative");
}

if (data.offset < 0) {
return Status::Invalid("Array offset is negative");
}

if (layout.variadic_spec) {
if (data.buffers.size() < layout.buffers.size()) {
return Status::Invalid("Expected at least ", layout.buffers.size(),
Expand Down
Loading