Skip to content

Commit a397003

Browse files
authored
Fixed out of bounds access (#7268)
1 parent ea1b205 commit a397003

File tree

1 file changed

+29
-23
lines changed

1 file changed

+29
-23
lines changed

ydb/library/yql/utils/parse_double.cpp

Lines changed: 29 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,38 @@ namespace {
99
template <typename T>
1010
bool GenericTryFloatFromString(TStringBuf buf, T& value) {
1111
value = 0;
12-
if (!buf.size() || !TryFromString(buf.data(), buf.size(), value)) {
13-
const char* ptr = buf.data();
14-
ui32 size = buf.size();
15-
char sign = '+';
16-
if (*ptr == '+' || *ptr == '-') {
17-
sign = *ptr;
18-
++ptr;
19-
--size;
20-
}
12+
if (!buf.size()) {
13+
return false;
14+
}
15+
16+
if (TryFromString(buf.data(), buf.size(), value)) {
17+
return true;
18+
}
19+
20+
const char* ptr = buf.data();
21+
ui32 size = buf.size();
22+
char sign = '+';
23+
if (*ptr == '+' || *ptr == '-') {
24+
sign = *ptr;
25+
++ptr;
26+
--size;
27+
}
2128

22-
if (size != 3) {
23-
return false;
24-
}
29+
if (size != 3) {
30+
return false;
31+
}
2532

26-
// NaN or Inf (ignoring case)
27-
if (AsciiToUpper(ptr[0]) == 'N' && AsciiToUpper(ptr[1]) == 'A' && AsciiToUpper(ptr[2]) == 'N') {
28-
value = std::numeric_limits<T>::quiet_NaN();
29-
} else if (AsciiToUpper(ptr[0]) == 'I' && AsciiToUpper(ptr[1]) == 'N' && AsciiToUpper(ptr[2]) == 'F') {
30-
value = std::numeric_limits<T>::infinity();
31-
} else {
32-
return false;
33-
}
33+
// NaN or Inf (ignoring case)
34+
if (AsciiToUpper(ptr[0]) == 'N' && AsciiToUpper(ptr[1]) == 'A' && AsciiToUpper(ptr[2]) == 'N') {
35+
value = std::numeric_limits<T>::quiet_NaN();
36+
} else if (AsciiToUpper(ptr[0]) == 'I' && AsciiToUpper(ptr[1]) == 'N' && AsciiToUpper(ptr[2]) == 'F') {
37+
value = std::numeric_limits<T>::infinity();
38+
} else {
39+
return false;
40+
}
3441

35-
if (sign == '-') {
36-
value = -value;
37-
}
42+
if (sign == '-') {
43+
value = -value;
3844
}
3945

4046
return true;

0 commit comments

Comments
 (0)