1
0
mirror of https://github.com/janet-lang/janet synced 2025-10-24 20:27:41 +00:00

Fix overflow in exponent estimation in strtod.c.

Found by OSS-Fuzz.
This commit is contained in:
Calvin Rose
2020-04-21 18:32:59 -05:00
parent 23b811243f
commit c876e63010
2 changed files with 6 additions and 3 deletions

View File

@@ -208,9 +208,9 @@ static double convert(
/* Approximate exponent in base 2 of mant and exponent. This should get us a good estimate of the final size of the
* number, within * 2^32 or so. */
int32_t mant_exp2_approx = mant->n * 32 + 16;
int32_t exp_exp2_approx = (int32_t)(floor(log2(base) * exponent));
int32_t exp2_approx = mant_exp2_approx + exp_exp2_approx;
int64_t mant_exp2_approx = mant->n * 32 + 16;
int64_t exp_exp2_approx = (int64_t)(floor(log2(base) * exponent));
int64_t exp2_approx = mant_exp2_approx + exp_exp2_approx;
/* Short circuit zero, huge, and small numbers. We use the exponent range of valid IEEE754 doubles (-1022, 1023)
* with a healthy buffer to allow for inaccuracies in the approximation and denormailzed numbers. */