Commit 45fc1486 authored by Jakob Kummerow's avatar Jakob Kummerow Committed by V8 LUCI CQ

[bigint] Max parts when parsing: fix off-by-one

The very last part skipped the max_digits check, and earlier parts
forgot to account for that in their check. The reason why the last
part originally got special treatment no longer applies, so we can
fix this bug by removing the special case, simplifying the overall
logic.

Fixed: chromium:1248972
Change-Id: I1857dd8b63c00f9bdfb9237f2ea3621ecc1339e2
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3160522
Auto-Submit: Jakob Kummerow <jkummerow@chromium.org>
Commit-Queue: Maya Lekova <mslekova@chromium.org>
Reviewed-by: 's avatarMaya Lekova <mslekova@chromium.org>
Cr-Commit-Position: refs/heads/main@{#76842}
parent 65998631
......@@ -392,7 +392,7 @@ class FromStringAccumulator {
digit_t radix);
// Step 3: Check if a result is available, and determine its required
// allocation size.
// allocation size (guaranteed to be <= max_digits passed to the constructor).
Result result() { return result_; }
int ResultLength() {
return std::max(stack_parts_used_, static_cast<int>(heap_parts_.size()));
......@@ -409,7 +409,7 @@ class FromStringAccumulator {
digit_t radix);
ALWAYS_INLINE bool AddPart(digit_t multiplier, digit_t part, bool is_last);
ALWAYS_INLINE bool AddPart(digit_t part, bool is_last);
ALWAYS_INLINE bool AddPart(digit_t part);
digit_t stack_parts_[kStackParts];
std::vector<digit_t> heap_parts_;
......@@ -485,7 +485,7 @@ const Char* FromStringAccumulator::ParsePowerTwo(const Char* current,
break;
}
}
if (!AddPart(part, done)) return current;
if (!AddPart(part)) return current;
} while (!done);
// We use the unused {last_multiplier_} field to
// communicate how many bits are unused in the last part.
......@@ -571,10 +571,10 @@ bool FromStringAccumulator::AddPart(digit_t multiplier, digit_t part,
BIGINT_H_DCHECK(max_multiplier_ == 0 || max_multiplier_ == multiplier);
max_multiplier_ = multiplier;
}
return AddPart(part, is_last);
return AddPart(part);
}
bool FromStringAccumulator::AddPart(digit_t part, bool is_last) {
bool FromStringAccumulator::AddPart(digit_t part) {
if (stack_parts_used_ < kStackParts) {
stack_parts_[stack_parts_used_++] = part;
return true;
......@@ -586,7 +586,7 @@ bool FromStringAccumulator::AddPart(digit_t part, bool is_last) {
heap_parts_.push_back(stack_parts_[i]);
}
}
if (static_cast<int>(heap_parts_.size()) >= max_digits_ && !is_last) {
if (static_cast<int>(heap_parts_.size()) >= max_digits_) {
result_ = Result::kMaxSizeExceeded;
return false;
}
......
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