From 7fc78f66102316e513c04d770b4535ded72bac9a Mon Sep 17 00:00:00 2001 From: neeldug <5161147+neeldug@users.noreply.github.com> Date: Sat, 21 Aug 2021 20:27:56 +0100 Subject: [PATCH] fix(boa): fixes panic on bigint size (#1415) --- boa/src/bigint.rs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/boa/src/bigint.rs b/boa/src/bigint.rs index c6330d20ab..2e2bca1d58 100644 --- a/boa/src/bigint.rs +++ b/boa/src/bigint.rs @@ -169,6 +169,15 @@ impl JsBigInt { return Err(context.construct_range_error("BigInt negative exponent")); }; + let num_bits = (x.inner.bits() as f64 + * y.to_f64().expect("Unable to convert from BigUInt to f64")) + .floor() + + 1f64; + + if num_bits > 1_000_000_000f64 { + return Err(context.construct_range_error("Maximum BigInt size exceeded")); + } + Ok(Self::new(x.inner.as_ref().clone().pow(y))) }