This fixes the "big exp" bug, although we need to assess the performance and maybe do some tuning. (#233)

This commit is contained in:
Daniel Lemire 2019-07-29 13:28:16 -04:00 committed by GitHub
parent a53d95099c
commit 85e31a5479
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 16 additions and 6 deletions

View File

@ -276,12 +276,17 @@ parse_float(const uint8_t *const buf,
expnumber = 10 * expnumber + digit; expnumber = 10 * expnumber + digit;
++p; ++p;
} }
if (is_integer(*p)) { while (is_integer(*p)) {
if(expnumber > 0x100000000) {// we need to check for overflows
// we refuse to parse this // we refuse to parse this
#ifdef JSON_TEST_NUMBERS // for unit testing #ifdef JSON_TEST_NUMBERS // for unit testing
foundInvalidNumber(buf + offset); foundInvalidNumber(buf + offset);
#endif #endif
return false; return false;
}
digit = *p - '0';
expnumber = 10 * expnumber + digit;
++p;
} }
if (unlikely(expnumber > 308)) { if (unlikely(expnumber > 308)) {
// this path is unlikely // this path is unlikely
@ -514,12 +519,17 @@ static really_inline bool parse_number(const uint8_t *const buf,
expnumber = 10 * expnumber + digit; expnumber = 10 * expnumber + digit;
++p; ++p;
} }
if (is_integer(*p)) { while (is_integer(*p)) {
if(expnumber > 0x100000000) {// we need to check for overflows
// we refuse to parse this // we refuse to parse this
#ifdef JSON_TEST_NUMBERS // for unit testing #ifdef JSON_TEST_NUMBERS // for unit testing
foundInvalidNumber(buf + offset); foundInvalidNumber(buf + offset);
#endif #endif
return false; return false;
}
digit = *p - '0';
expnumber = 10 * expnumber + digit;
++p;
} }
exponent += (negexp ? -expnumber : expnumber); exponent += (negexp ? -expnumber : expnumber);
} }