Skip to content

Commit f5e5d47

Browse files
committed
Properly test for overflow
Do not use an approximation to do this. Instead check if the result is Inf.
1 parent d83d2ba commit f5e5d47

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

include/rapidjson/reader.h

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1561,8 +1561,6 @@ class GenericReader {
15611561
// Force double for big integer
15621562
if (useDouble) {
15631563
while (RAPIDJSON_LIKELY(s.Peek() >= '0' && s.Peek() <= '9')) {
1564-
if (RAPIDJSON_UNLIKELY(d >= 1.7976931348623157e307)) // DBL_MAX / 10.0
1565-
RAPIDJSON_PARSE_ERROR(kParseErrorNumberTooBig, startOffset);
15661564
d = d * 10 + (s.TakePush() - '0');
15671565
}
15681566
}
@@ -1702,6 +1700,12 @@ class GenericReader {
17021700
else
17031701
d = internal::StrtodNormalPrecision(d, p);
17041702

1703+
if (d == std::numeric_limits<double>::infinity()) {
1704+
// Overflow
1705+
// TODO: internal::StrtodX should report overflow (or underflow)
1706+
RAPIDJSON_PARSE_ERROR(kParseErrorNumberTooBig, startOffset);
1707+
}
1708+
17051709
cont = handler.Double(minus ? -d : d);
17061710
}
17071711
else if (useNanOrInf) {

0 commit comments

Comments
 (0)