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 out-of-bounds memory write in decimal128-to-string conversion #9740

Merged
merged 2 commits into from
Nov 22, 2021
Merged
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
7 changes: 4 additions & 3 deletions cpp/src/strings/convert/utilities.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ __device__ inline size_type integer_to_string(IntegerType value, char* d_buffer)
bool const is_negative = cuda::std::is_signed<IntegerType>() ? (value < 0) : false;

constexpr IntegerType base = 10;
constexpr int MAX_DIGITS = 20; // largest 64-bit integer is 20 digits
char digits[MAX_DIGITS]; // place-holder for digit chars
// largest 64-bit integer is 20 digits; largest 128-bit integer is 39 digits
constexpr int MAX_DIGITS = cuda::std::numeric_limits<IntegerType>::digits10 + 1;
char digits[MAX_DIGITS]; // place-holder for digit chars
int digits_idx = 0;
while (value != 0) {
assert(digits_idx < MAX_DIGITS);
Expand Down Expand Up @@ -107,7 +108,7 @@ constexpr size_type count_digits(IntegerType value)
auto const digits = [value] {
// largest 8-byte unsigned value is 18446744073709551615 (20 digits)
// largest 16-byte unsigned value is 340282366920938463463374607431768211455 (39 digits)
auto constexpr max_digits = std::is_same_v<IntegerType, __int128_t> ? 39 : 20;
auto constexpr max_digits = cuda::std::numeric_limits<IntegerType>::digits10 + 1;

size_type digits = 1;
__int128_t pow10 = 10;
Expand Down
4 changes: 4 additions & 0 deletions cpp/tests/strings/fixed_point_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,11 @@ TEST_F(StringsConvertTest, IsFixedPoint)
CUDF_TEST_EXPECT_COLUMNS_EQUIVALENT(*results, expected64_scaled);
}

#ifdef NDEBUG
TEST_F(StringsConvertTest, FixedPointStringConversionOperator)
#else
TEST_F(StringsConvertTest, DISABLED_FixedPointStringConversionOperator)
#endif
{
auto const max = cuda::std::numeric_limits<__int128_t>::max();

Expand Down