Commit 3e64f2cf authored by Igor Sheludko's avatar Igor Sheludko Committed by V8 LUCI CQ

[bigint] Fix BigInt size calculation on 32-bit architectures

Bug: chromium:1209723
Change-Id: Ied077c7819312ea71d58997378d7c3f4acb02566
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2928193Reviewed-by: 's avatarJakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Igor Sheludko <ishell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#74865}
parent cb25099b
......@@ -1890,13 +1890,14 @@ MaybeHandle<FreshlyAllocatedBigInt> BigInt::AllocateFor(
DCHECK(2 <= radix && radix <= 36);
DCHECK_GE(charcount, 0);
size_t bits_per_char = kMaxBitsPerChar[radix];
size_t chars = static_cast<size_t>(charcount);
uint64_t chars = static_cast<uint64_t>(charcount);
const int roundup = kBitsPerCharTableMultiplier - 1;
if (chars <= (std::numeric_limits<size_t>::max() - roundup) / bits_per_char) {
size_t bits_min = bits_per_char * chars;
if (chars <=
(std::numeric_limits<uint64_t>::max() - roundup) / bits_per_char) {
uint64_t bits_min = bits_per_char * chars;
// Divide by 32 (see table), rounding up.
bits_min = (bits_min + roundup) >> kBitsPerCharTableShift;
if (bits_min <= static_cast<size_t>(kMaxInt)) {
if (bits_min <= static_cast<uint64_t>(kMaxInt)) {
// Divide by kDigitsBits, rounding up.
int length = static_cast<int>((bits_min + kDigitBits - 1) / kDigitBits);
if (length <= kMaxLength) {
......
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