diff --git a/cpp/src/arrow/array/array_list_test.cc b/cpp/src/arrow/array/array_list_test.cc index 4901a1e6fa6a..5ce084d756d8 100644 --- a/cpp/src/arrow/array/array_list_test.cc +++ b/cpp/src/arrow/array/array_list_test.cc @@ -1794,6 +1794,17 @@ TEST_F(TestFixedSizeListArray, NotEnoughValues) { values = ArrayFromJSON(value_type_, "[1, 2, 3, 4]"); result_ = std::make_shared(type_, 1, values); ASSERT_OK(result_->ValidateFull()); + + // The array offset must be taken into account + result_ = + std::make_shared(type_, 1, values, /*null_bitmap=*/nullptr, + /*null_count=*/0, /*offset=*/1); + ASSERT_OK(result_->ValidateFull()); + result_ = + std::make_shared(type_, 1, values, /*null_bitmap=*/nullptr, + /*null_count=*/0, /*offset=*/2); + ASSERT_RAISES(Invalid, result_->Validate()); + ASSERT_RAISES(Invalid, result_->ValidateFull()); } TEST_F(TestFixedSizeListArray, FlattenZeroLength) { diff --git a/cpp/src/arrow/array/validate.cc b/cpp/src/arrow/array/validate.cc index 16bc9187af46..cdf20d934135 100644 --- a/cpp/src/arrow/array/validate.cc +++ b/cpp/src/arrow/array/validate.cc @@ -290,11 +290,12 @@ struct ValidateArrayImpl { } int64_t expected_values_length = -1; - if (MultiplyWithOverflow(data.length, list_size, &expected_values_length) || + if (MultiplyWithOverflow(data.length + data.offset, list_size, + &expected_values_length) || values.length < expected_values_length) { - return Status::Invalid("Values length (", values.length, - ") is less than the length (", data.length, - ") multiplied by the value size (", list_size, ")"); + return Status::Invalid( + "Values length (", values.length, ") is less than the length plus offset (", + data.length + data.offset, ") multiplied by the value size (", list_size, ")"); } const Status child_valid = RecurseInto(values); diff --git a/cpp/src/arrow/c/bridge_test.cc b/cpp/src/arrow/c/bridge_test.cc index 9a4d104d0004..7e69f1f2e1ef 100644 --- a/cpp/src/arrow/c/bridge_test.cc +++ b/cpp/src/arrow/c/bridge_test.cc @@ -3156,7 +3156,7 @@ TEST_F(TestArrayImport, ListWithOffset) { FillListLike(4, 0, 1, list_buffers_no_nulls1); CheckImport(ArrayFromJSON(list(int8()), "[[], [3, 4, 5], [6], [7, 8]]")); - FillPrimitive(AddChild(), 9, 0, 0, primitive_buffers_no_nulls1_8); + FillPrimitive(AddChild(), 12, 0, 0, primitive_buffers_no_nulls1_8); FillFixedSizeListLike(3, 0, 1, buffers_no_nulls_no_data); CheckImport( ArrayFromJSON(fixed_size_list(int8(), 3), "[[4, 5, 6], [7, 8, 9], [10, 11, 12]]")); @@ -3166,7 +3166,7 @@ TEST_F(TestArrayImport, ListWithOffset) { FillListLike(4, 0, 1, list_buffers_no_nulls1); CheckImport(ArrayFromJSON(list(int8()), "[[], [5, 6, 7], [8], [9, 10]]")); - FillPrimitive(AddChild(), 9, 0, 2, primitive_buffers_no_nulls1_8); + FillPrimitive(AddChild(), 12, 0, 2, primitive_buffers_no_nulls1_8); FillFixedSizeListLike(3, 0, 1, buffers_no_nulls_no_data); CheckImport(ArrayFromJSON(fixed_size_list(int8(), 3), "[[6, 7, 8], [9, 10, 11], [12, 13, 14]]"));