Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for integer overflow in contiguous-split #10437

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
5 changes: 3 additions & 2 deletions cpp/src/copying/contiguous_split.cu
Original file line number Diff line number Diff line change
Expand Up @@ -821,7 +821,8 @@ void copy_data(int num_bufs,
chunks.begin(),
[desired_chunk_size] __device__(dst_buf_info const& buf) -> thrust::pair<size_t, size_t> {
// Total bytes for this incoming partition
size_t const bytes = buf.num_elements * buf.element_size;
size_t const bytes =
static_cast<size_t>(buf.num_elements) * static_cast<size_t>(buf.element_size);
PointKernel marked this conversation as resolved.
Show resolved Hide resolved

// This clause handles nested data types (e.g. list or string) that store no data in the roow
// columns, only in their children.
Expand Down Expand Up @@ -1258,4 +1259,4 @@ std::vector<packed_table> contiguous_split(cudf::table_view const& input,
return cudf::detail::contiguous_split(input, splits, rmm::cuda_stream_default, mr);
}

}; // namespace cudf
}; // namespace cudf
11 changes: 10 additions & 1 deletion cpp/tests/copying/split_tests.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2019-2021, NVIDIA CORPORATION.
* Copyright (c) 2019-2022, NVIDIA CORPORATION.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -1357,6 +1357,15 @@ TEST_F(ContiguousSplitUntypedTest, ValidityEdgeCase)
}
}

TEST_F(ContiguousSplitUntypedTest, CalculationOverflow)
{
// tests an edge case where buf.elements * buf.element_size overflows an INT32.
auto col = cudf::make_fixed_width_column(
cudf::data_type{cudf::type_id::INT64}, 400 * 1024 * 1024, cudf::mask_state::UNALLOCATED);
auto result = cudf::contiguous_split(cudf::table_view{{*col}}, {});
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*col, result[0].table.column(0));
}

// contiguous split with strings
struct ContiguousSplitStringTableTest : public SplitTest<std::string> {
};
Expand Down