1
0
mirror of https://github.com/janet-lang/janet synced 2024-11-28 11:09:54 +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 /* 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. */ * number, within * 2^32 or so. */
int32_t mant_exp2_approx = mant->n * 32 + 16; int64_t mant_exp2_approx = mant->n * 32 + 16;
int32_t exp_exp2_approx = (int32_t)(floor(log2(base) * exponent)); int64_t exp_exp2_approx = (int64_t)(floor(log2(base) * exponent));
int32_t exp2_approx = mant_exp2_approx + exp_exp2_approx; 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) /* 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. */ * with a healthy buffer to allow for inaccuracies in the approximation and denormailzed numbers. */

View File

@ -241,4 +241,7 @@ neldb\0\0\0\xD8\x05printG\x01\0\xDE\xDE\xDE'\x03\0marshal_tes/\x02
(assert (nil? (first @"")) "in vs get 1") (assert (nil? (first @"")) "in vs get 1")
(assert (nil? (last @"")) "in vs get 1") (assert (nil? (last @"")) "in vs get 1")
# For undefined behavior sanitizer
0xf&1fffFFFF
(end-suite) (end-suite)