Skip to content

Commit bf572c7

Browse files
addaleaxrefack
authored andcommitted
deps: V8: cherry-pick 91f0cd0
Original commit message: [ubsan] Fix various ClusterFuzz-found issues Fixing a few float and int overflows. Drive-by fix: with --experimental-wasm-bigint, Number values may not be used to initialize i64-typed globals. The existing code for doing that relied on UB; since it's a spec violation the fix is to throw instead. No regression test for 933103 because it will OOM anyway. No regression test for 932896 because it would be extremely slow. Bug: chromium:927894, chromium:927996, chromium:930086, chromium:932679, chromium:932896, chromium:933103, chromium:933134 Change-Id: Iae1c1ff1038af4512a52d3e56b8c4b75f2233314 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1495911 Commit-Queue: Jakob Kummerow <jkummerow@chromium.org> Reviewed-by: Michael Starzinger <mstarzinger@chromium.org> Reviewed-by: Adam Klein <adamk@chromium.org> Cr-Commit-Position: refs/heads/master@{#60075} Refs: v8/v8@91f0cd0 PR-URL: #26685 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Refael Ackermann <refack@gmail.com>
1 parent 09f134f commit bf572c7

10 files changed

Lines changed: 105 additions & 25 deletions

File tree

common.gypi

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
# Reset this number to 0 on major V8 upgrades.
3939
# Increment by one for each non-official patch applied to deps/v8.
40-
'v8_embedder_string': '-node.2',
40+
'v8_embedder_string': '-node.3',
4141

4242
##### V8 defaults for Node.js #####
4343

deps/v8/include/v8.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10939,7 +10939,11 @@ int64_t Isolate::AdjustAmountOfExternalAllocatedMemory(
1093910939
reinterpret_cast<int64_t*>(reinterpret_cast<uint8_t*>(this) +
1094010940
I::kExternalMemoryAtLastMarkCompactOffset);
1094110941

10942-
const int64_t amount = *external_memory + change_in_bytes;
10942+
// Embedders are weird: we see both over- and underflows here. Perform the
10943+
// addition with unsigned types to avoid undefined behavior.
10944+
const int64_t amount =
10945+
static_cast<int64_t>(static_cast<uint64_t>(change_in_bytes) +
10946+
static_cast<uint64_t>(*external_memory));
1094310947
*external_memory = amount;
1094410948

1094510949
int64_t allocation_diff_since_last_mc =

deps/v8/src/builtins/builtins-string.cc

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,12 @@ BUILTIN(StringRaw) {
448448
Object::ToLength(isolate, raw_len));
449449

450450
IncrementalStringBuilder result_builder(isolate);
451-
const uint32_t length = static_cast<uint32_t>(raw_len->Number());
451+
// Intentional spec violation: we ignore {length} values >= 2^32, because
452+
// assuming non-empty chunks they would generate too-long strings anyway.
453+
const double raw_len_number = raw_len->Number();
454+
const uint32_t length = raw_len_number > std::numeric_limits<uint32_t>::max()
455+
? std::numeric_limits<uint32_t>::max()
456+
: static_cast<uint32_t>(raw_len_number);
452457
if (length > 0) {
453458
Handle<Object> first_element;
454459
ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, first_element,

deps/v8/src/builtins/builtins-typed-array.cc

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,18 @@ BUILTIN(TypedArrayPrototypeBuffer) {
2727
namespace {
2828

2929
int64_t CapRelativeIndex(Handle<Object> num, int64_t minimum, int64_t maximum) {
30-
int64_t relative;
3130
if (V8_LIKELY(num->IsSmi())) {
32-
relative = Smi::ToInt(*num);
31+
int64_t relative = Smi::ToInt(*num);
32+
return relative < 0 ? std::max<int64_t>(relative + maximum, minimum)
33+
: std::min<int64_t>(relative, maximum);
3334
} else {
3435
DCHECK(num->IsHeapNumber());
35-
double fp = HeapNumber::cast(*num)->value();
36-
if (V8_UNLIKELY(!std::isfinite(fp))) {
37-
// +Infinity / -Infinity
38-
DCHECK(!std::isnan(fp));
39-
return fp < 0 ? minimum : maximum;
40-
}
41-
relative = static_cast<int64_t>(fp);
36+
double relative = HeapNumber::cast(*num)->value();
37+
DCHECK(!std::isnan(relative));
38+
return static_cast<int64_t>(
39+
relative < 0 ? std::max<double>(relative + maximum, minimum)
40+
: std::min<double>(relative, maximum));
4241
}
43-
return relative < 0 ? std::max<int64_t>(relative + maximum, minimum)
44-
: std::min<int64_t>(relative, maximum);
4542
}
4643

4744
} // namespace