Skip to content

Commit

Permalink
Fix integer overflow in indexalator pointer logic (#16643)
Browse files Browse the repository at this point in the history
Fixes integer overflow in the indexalator logic when incrementing/decrementing its data pointer. Any sufficiently large int32 input values used in computing the byte-pointer position causes an overflow when multiplying the value by the byte-width of the underlying index type. For example, this overflow would occur when accessing rows greater than 536,870,912 with an underlying index type of int32 (4-bytes).

Authors:
  - David Wendt (https://github.com/davidwendt)

Approvers:
  - Bradley Dice (https://github.com/bdice)
  - Paul Mattione (https://github.com/pmattione-nvidia)

URL: #16643
  • Loading branch information
davidwendt authored Aug 27, 2024
1 parent c4591c0 commit 115ddce
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions cpp/include/cudf/detail/indexalator.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ struct input_indexalator : base_normalator<input_indexalator, cudf::size_type> {
*/
__device__ inline cudf::size_type operator[](size_type idx) const
{
void const* tp = p_ + (idx * this->width_);
void const* tp = p_ + (static_cast<std::ptrdiff_t>(idx) * this->width_);
return type_dispatcher(this->dtype_, normalize_type{}, tp);
}

Expand All @@ -109,7 +109,7 @@ struct input_indexalator : base_normalator<input_indexalator, cudf::size_type> {
CUDF_HOST_DEVICE input_indexalator(void const* data, data_type dtype, cudf::size_type offset = 0)
: base_normalator<input_indexalator, cudf::size_type>(dtype), p_{static_cast<char const*>(data)}
{
p_ += offset * this->width_;
p_ += static_cast<std::ptrdiff_t>(offset) * this->width_;
}

protected:
Expand Down Expand Up @@ -165,7 +165,7 @@ struct output_indexalator : base_normalator<output_indexalator, cudf::size_type>
__device__ inline output_indexalator const operator[](size_type idx) const
{
output_indexalator tmp{*this};
tmp.p_ += (idx * this->width_);
tmp.p_ += static_cast<std::ptrdiff_t>(idx) * this->width_;
return tmp;
}

Expand Down

0 comments on commit 115ddce

Please sign in to comment.