diff options
author | Vitaly Stoyan <vvvv@ydb.tech> | 2024-07-31 01:26:52 +0300 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-07-31 01:26:52 +0300 |
commit | a397003e91a3059c73ac9078d7d359547f356037 (patch) | |
tree | 3399afccb719e9fb66247307ac972d8e907ad0a3 | |
parent | ea1b205d749cc1c3e37c7ae42817534ede33e390 (diff) | |
download | ydb-a397003e91a3059c73ac9078d7d359547f356037.tar.gz |
Fixed out of bounds access (#7268)
-rw-r--r-- | ydb/library/yql/utils/parse_double.cpp | 52 |
1 files changed, 29 insertions, 23 deletions
diff --git a/ydb/library/yql/utils/parse_double.cpp b/ydb/library/yql/utils/parse_double.cpp index 0c06ad9544..90923160c5 100644 --- a/ydb/library/yql/utils/parse_double.cpp +++ b/ydb/library/yql/utils/parse_double.cpp @@ -9,32 +9,38 @@ namespace { template <typename T> bool GenericTryFloatFromString(TStringBuf buf, T& value) { value = 0; - if (!buf.size() || !TryFromString(buf.data(), buf.size(), value)) { - const char* ptr = buf.data(); - ui32 size = buf.size(); - char sign = '+'; - if (*ptr == '+' || *ptr == '-') { - sign = *ptr; - ++ptr; - --size; - } + if (!buf.size()) { + return false; + } + + if (TryFromString(buf.data(), buf.size(), value)) { + return true; + } + + const char* ptr = buf.data(); + ui32 size = buf.size(); + char sign = '+'; + if (*ptr == '+' || *ptr == '-') { + sign = *ptr; + ++ptr; + --size; + } - if (size != 3) { - return false; - } + if (size != 3) { + return false; + } - // NaN or Inf (ignoring case) - if (AsciiToUpper(ptr[0]) == 'N' && AsciiToUpper(ptr[1]) == 'A' && AsciiToUpper(ptr[2]) == 'N') { - value = std::numeric_limits<T>::quiet_NaN(); - } else if (AsciiToUpper(ptr[0]) == 'I' && AsciiToUpper(ptr[1]) == 'N' && AsciiToUpper(ptr[2]) == 'F') { - value = std::numeric_limits<T>::infinity(); - } else { - return false; - } + // NaN or Inf (ignoring case) + if (AsciiToUpper(ptr[0]) == 'N' && AsciiToUpper(ptr[1]) == 'A' && AsciiToUpper(ptr[2]) == 'N') { + value = std::numeric_limits<T>::quiet_NaN(); + } else if (AsciiToUpper(ptr[0]) == 'I' && AsciiToUpper(ptr[1]) == 'N' && AsciiToUpper(ptr[2]) == 'F') { + value = std::numeric_limits<T>::infinity(); + } else { + return false; + } - if (sign == '-') { - value = -value; - } + if (sign == '-') { + value = -value; } return true; |