Skip to content
Open
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
26 changes: 26 additions & 0 deletions cpp/src/arrow/compute/kernels/scalar_temporal_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,32 @@ TEST_F(ScalarTemporalTest, TestIsLeapYear) {
is_leap_year_pago_pago);
}

// GH-55743: year_month_day used to reserve a single element per child builder
// and then append without bounds checks, overflowing for inputs longer than
// the builders' minimum capacity (32 elements).
TEST_F(ScalarTemporalTest, YearMonthDayLongInput) {
const int32_t length = 100;
std::vector<int32_t> days(length);
std::vector<bool> is_valid(length);
for (int32_t i = 0; i < length; ++i) {
days[i] = i;
is_valid[i] = (i % 7 != 3);
}
std::shared_ptr<Array> input;
ArrayFromVector<Date32Type>(is_valid, days, &input);

ASSERT_OK_AND_ASSIGN(Datum year, CallFunction("year", {input}));
ASSERT_OK_AND_ASSIGN(Datum month, CallFunction("month", {input}));
ASSERT_OK_AND_ASSIGN(Datum day, CallFunction("day", {input}));
ASSERT_OK_AND_ASSIGN(
auto expected,
StructArray::Make({year.make_array(), month.make_array(), day.make_array()},
{"year", "month", "day"}, input->null_bitmap()));

ASSERT_OK_AND_ASSIGN(Datum actual, CallFunction("year_month_day", {input}));
AssertArraysEqual(*expected, *actual.make_array(), /*verbose=*/true);
}

TEST_F(ScalarTemporalTest, TestZoned1) {
std::vector<std::string> timezones = {"Pacific/Marquesas", "-09:30"};
for (const auto& timezone : timezones) {
Expand Down
2 changes: 1 addition & 1 deletion cpp/src/arrow/compute/kernels/scalar_temporal_unary.cc
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ struct YearMonthDay {
for (int i = 0; i < 3; i++) {
field_builders.push_back(
checked_cast<BuilderType*>(struct_builder->field_builder(i)));
RETURN_NOT_OK(field_builders[i]->Reserve(1));
RETURN_NOT_OK(field_builders[i]->Reserve(in.length));
}
auto visit_null = [&]() { return struct_builder->AppendNull(); };
std::function<Status(typename InType::c_type arg)> visit_value;
Expand Down
Loading