Skip to content

Commit

Permalink
Fix out-of-bounds memory write in decimal128-to-string conversion (#9740
Browse files Browse the repository at this point in the history
)

This fixes an error found in a memcheck test referenced here: https://gpuci.gpuopenanalytics.com/job/rapidsai/job/gpuci/job/cudf/job/prb/job/cudf-gpu-test/CUDA=11.5,GPU_LABEL=cuda115,LINUX_VER=centos7,PYTHON=3.8/5082/

This also disables the `FixedPointStringConversionOperator` which fails on a Debug build and may be a bug in `std::string`.

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

Approvers:
  - Jake Hemstad (https://github.com/jrhemstad)
  - Conor Hoekstra (https://github.com/codereport)

URL: #9740
  • Loading branch information
davidwendt authored Nov 22, 2021
1 parent cac53c5 commit ebeb202
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
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

0 comments on commit ebeb202

Please sign in to comment.