From f5e5d47fac0f654749c4d6267015005b74643dff Mon Sep 17 00:00:00 2001 From: abolz Date: Fri, 15 Jun 2018 11:29:48 +0200 Subject: [PATCH] Properly test for overflow Do not use an approximation to do this. Instead check if the result is Inf. --- include/rapidjson/reader.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/include/rapidjson/reader.h b/include/rapidjson/reader.h index f95aef4..69baef5 100644 --- a/include/rapidjson/reader.h +++ b/include/rapidjson/reader.h @@ -1561,8 +1561,6 @@ private: // Force double for big integer if (useDouble) { while (RAPIDJSON_LIKELY(s.Peek() >= '0' && s.Peek() <= '9')) { - if (RAPIDJSON_UNLIKELY(d >= 1.7976931348623157e307)) // DBL_MAX / 10.0 - RAPIDJSON_PARSE_ERROR(kParseErrorNumberTooBig, startOffset); d = d * 10 + (s.TakePush() - '0'); } } @@ -1702,6 +1700,12 @@ private: else d = internal::StrtodNormalPrecision(d, p); + if (d == std::numeric_limits::infinity()) { + // Overflow + // TODO: internal::StrtodX should report overflow (or underflow) + RAPIDJSON_PARSE_ERROR(kParseErrorNumberTooBig, startOffset); + } + cont = handler.Double(minus ? -d : d); } else if (useNanOrInf) {