Commit 62bdde92 authored by Jakob Kummerow's avatar Jakob Kummerow Committed by Commit Bot

[bigint] Fix cornercase in BigInt.asUintN

One of the early (no-op) returns forgot to check whether the
number of existing digits equals the number of required digits.

Bug: chromium:936506
Change-Id: Ic9a5b927306de3cd6b26662785ac11d866e12026
Reviewed-on: https://chromium-review.googlesource.com/c/1493133Reviewed-by: 's avatarAdam Klein <adamk@chromium.org>
Commit-Queue: Jakob Kummerow <jkummerow@chromium.org>
Cr-Commit-Position: refs/heads/master@{#59929}
parent e6debb13
...@@ -2261,9 +2261,8 @@ MaybeHandle<BigInt> BigInt::AsUintN(Isolate* isolate, uint64_t n, ...@@ -2261,9 +2261,8 @@ MaybeHandle<BigInt> BigInt::AsUintN(Isolate* isolate, uint64_t n,
int needed_length = static_cast<int>((n + kDigitBits - 1) / kDigitBits); int needed_length = static_cast<int>((n + kDigitBits - 1) / kDigitBits);
if (x->length() < needed_length) return x; if (x->length() < needed_length) return x;
int bits_in_top_digit = n % kDigitBits; int bits_in_top_digit = n % kDigitBits;
if (bits_in_top_digit == 0) { if (x->length() == needed_length) {
if (x->length() == needed_length) return x; if (bits_in_top_digit == 0) return x;
} else {
digit_t top_digit = x->digit(needed_length - 1); digit_t top_digit = x->digit(needed_length - 1);
if ((top_digit >> bits_in_top_digit) == 0) return x; if ((top_digit >> bits_in_top_digit) == 0) return x;
} }
......
...@@ -297,4 +297,8 @@ ...@@ -297,4 +297,8 @@
}{ }{
assertThrows(() => BigInt.asUintN(3, 12), TypeError); assertThrows(() => BigInt.asUintN(3, 12), TypeError);
assertEquals(4n, BigInt.asUintN(3, "12")); assertEquals(4n, BigInt.asUintN(3, "12"));
}{
// crbug.com/936506
assertEquals(1n, BigInt.asUintN(15, 0x100000001n));
assertEquals(1n, BigInt.asUintN(15, 0x10000000000000001n));
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment