Skip to content

Commit

Permalink
fix(boa): fixes panic on bigint size
Browse files Browse the repository at this point in the history
- adds crude memory check on bigint bitsize
- throws range error if exceeds 1B bits

Closes #1401
  • Loading branch information
neeldug committed Jul 25, 2021
1 parent beecb2d commit 47276a5
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions boa/src/bigint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,12 @@ impl JsBigInt {
return Err(context.construct_range_error("BigInt negative exponent"));
};

let num_bits= (y.to_f64().expect("Unable to convert from BigUInt to f64") * x.inner.bits() as 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)))
}

Expand Down

0 comments on commit 47276a5

Please sign in to comment.