[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/1493133 Reviewed-by: Adam Klein <adamk@chromium.org> Commit-Queue: Jakob Kummerow <jkummerow@chromium.org> Cr-Commit-Position: refs/heads/master@{#59929}
This commit is contained in:
parent
e6debb13bb
commit
62bdde9242
@ -2261,9 +2261,8 @@ MaybeHandle<BigInt> BigInt::AsUintN(Isolate* isolate, uint64_t n,
|
||||
int needed_length = static_cast<int>((n + kDigitBits - 1) / kDigitBits);
|
||||
if (x->length() < needed_length) return x;
|
||||
int bits_in_top_digit = n % kDigitBits;
|
||||
if (bits_in_top_digit == 0) {
|
||||
if (x->length() == needed_length) return x;
|
||||
} else {
|
||||
if (x->length() == needed_length) {
|
||||
if (bits_in_top_digit == 0) return x;
|
||||
digit_t top_digit = x->digit(needed_length - 1);
|
||||
if ((top_digit >> bits_in_top_digit) == 0) return x;
|
||||
}
|
||||
|
@ -297,4 +297,8 @@
|
||||
}{
|
||||
assertThrows(() => BigInt.asUintN(3, 12), TypeError);
|
||||
assertEquals(4n, BigInt.asUintN(3, "12"));
|
||||
}{
|
||||
// crbug.com/936506
|
||||
assertEquals(1n, BigInt.asUintN(15, 0x100000001n));
|
||||
assertEquals(1n, BigInt.asUintN(15, 0x10000000000000001n));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user