Skip to content

Commit 3589dc2

Browse files
authored
GH-50010: [C++][Parquet] Fix undefined behavior in TypedColumnWriterImpl::UpdateLevelHistogram (#50011)
### Rationale for this change Fix an undefined behavior. ### What changes are included in this PR? It fixes the undefined behavior by delaying the span construction. ### Are these changes tested? Yes. ### Are there any user-facing changes? No. * GitHub Issue: #50010 Authored-by: Zehua Zou <zehuazou2000@gmail.com> Signed-off-by: Gang Wu <ustcwg@gmail.com>
1 parent 52a51ea commit 3589dc2

1 file changed

Lines changed: 6 additions & 7 deletions

File tree

cpp/src/parquet/column_writer.cc

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1807,20 +1807,19 @@ class TypedColumnWriterImpl : public ColumnWriterImpl,
18071807
return;
18081808
}
18091809

1810-
auto add_levels = [](std::vector<int64_t>& level_histogram,
1811-
std::span<const int16_t> levels, int16_t max_level) {
1810+
auto add_levels = [](std::vector<int64_t>& level_histogram, const int16_t* levels,
1811+
int64_t num_levels, int16_t max_level) {
18121812
if (max_level == 0) {
18131813
return;
18141814
}
18151815
ARROW_DCHECK_EQ(static_cast<size_t>(max_level) + 1, level_histogram.size());
1816-
::parquet::UpdateLevelHistogram(levels, level_histogram);
1816+
std::span<const int16_t> level_span{levels, static_cast<size_t>(num_levels)};
1817+
::parquet::UpdateLevelHistogram(level_span, level_histogram);
18171818
};
18181819

1819-
add_levels(page_size_statistics_->definition_level_histogram,
1820-
{def_levels, static_cast<size_t>(num_levels)},
1820+
add_levels(page_size_statistics_->definition_level_histogram, def_levels, num_levels,
18211821
descr_->max_definition_level());
1822-
add_levels(page_size_statistics_->repetition_level_histogram,
1823-
{rep_levels, static_cast<size_t>(num_levels)},
1822+
add_levels(page_size_statistics_->repetition_level_histogram, rep_levels, num_levels,
18241823
descr_->max_repetition_level());
18251824
}
18261825

0 commit comments

Comments
 (0)