From 85e31a5479353ed78d1df8e162fbfc55f70bc401 Mon Sep 17 00:00:00 2001 From: Daniel Lemire Date: Mon, 29 Jul 2019 13:28:16 -0400 Subject: [PATCH] This fixes the "big exp" bug, although we need to assess the performance and maybe do some tuning. (#233) --- include/simdjson/numberparsing.h | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/include/simdjson/numberparsing.h b/include/simdjson/numberparsing.h index 9a3519a5..eae709eb 100644 --- a/include/simdjson/numberparsing.h +++ b/include/simdjson/numberparsing.h @@ -276,12 +276,17 @@ parse_float(const uint8_t *const buf, expnumber = 10 * expnumber + digit; ++p; } - if (is_integer(*p)) { + while (is_integer(*p)) { + if(expnumber > 0x100000000) {// we need to check for overflows // we refuse to parse this #ifdef JSON_TEST_NUMBERS // for unit testing - foundInvalidNumber(buf + offset); + foundInvalidNumber(buf + offset); #endif - return false; + return false; + } + digit = *p - '0'; + expnumber = 10 * expnumber + digit; + ++p; } if (unlikely(expnumber > 308)) { // this path is unlikely @@ -514,12 +519,17 @@ static really_inline bool parse_number(const uint8_t *const buf, expnumber = 10 * expnumber + digit; ++p; } - if (is_integer(*p)) { + while (is_integer(*p)) { + if(expnumber > 0x100000000) {// we need to check for overflows // we refuse to parse this #ifdef JSON_TEST_NUMBERS // for unit testing - foundInvalidNumber(buf + offset); + foundInvalidNumber(buf + offset); #endif - return false; + return false; + } + digit = *p - '0'; + expnumber = 10 * expnumber + digit; + ++p; } exponent += (negexp ? -expnumber : expnumber); }