Skip to content

Commit

Permalink
Fix overflow check in cudf::merge (#14345)
Browse files Browse the repository at this point in the history
#14250 added a check to ensure `cudf::merge` throws when the total number of merged rows exceed `cudf::size_type` limit, however @bdice pointed out that the check was not correct because the accumulation was still occurring in `cudf::size_type`. This PR computes the accumulation in `std::size_t`.

Authors:
  - Divye Gala (https://github.com/divyegala)

Approvers:
  - Bradley Dice (https://github.com/bdice)
  - MithunR (https://github.com/mythrocks)
  - Nghia Truong (https://github.com/ttnghia)

URL: #14345
  • Loading branch information
divyegala authored Oct 31, 2023
1 parent cb06c20 commit ec080eb
Showing 1 changed file with 8 additions and 7 deletions.
15 changes: 8 additions & 7 deletions cpp/src/merge/merge.cu
Original file line number Diff line number Diff line change
Expand Up @@ -638,13 +638,14 @@ table_ptr_type merge(std::vector<table_view> const& tables_to_merge,

CUDF_EXPECTS(key_cols.size() == column_order.size(),
"Mismatched size between key_cols and column_order");
CUDF_EXPECTS(std::accumulate(tables_to_merge.cbegin(),
tables_to_merge.cend(),
cudf::size_type{0},
[](auto const& running_sum, auto const& tbl) {
return running_sum + tbl.num_rows();
}) <= std::numeric_limits<cudf::size_type>::max(),
"Total number of merged rows exceeds row limit");
CUDF_EXPECTS(
std::accumulate(tables_to_merge.cbegin(),
tables_to_merge.cend(),
std::size_t{0},
[](auto const& running_sum, auto const& tbl) {
return running_sum + static_cast<std::size_t>(tbl.num_rows());
}) <= static_cast<std::size_t>(std::numeric_limits<cudf::size_type>::max()),
"Total number of merged rows exceeds row limit");

// This utility will ensure all corresponding dictionary columns have matching keys.
// It will return any new dictionary columns created as well as updated table_views.
Expand Down

0 comments on commit ec080eb

Please sign in to comment.