deps: V8: backport 93cd21e8254b

Original commit message:

    skip fast transition path for escaped keys

    JSDataObjectBuilder's fast transition path previously compared undecoded
    source bytes of an escaped key against existing transitions.
    GetKeyChars() returned undecoded source bytes sliced using the decoded
    length, so escaped keys could incorrectly match persisted transitions
    and corrupt the keys of subsequent JSON.parse() calls.

    This patch fixes it by skipping the fast path when the key has escape
    characters.

    Co-Authored-By: 3zrvvv@gmail.com
    Bug: 521080746
    Change-Id: I77720cc34758180224ca8e0e5de0af48556ed013
    Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/8412610
    Commit-Queue: Joyee Cheung <joyee@igalia.com>
    Reviewed-by: Leszek Swirski <leszeks@chromium.org>
    Cr-Commit-Position: refs/heads/main@{#109925}

Refs: https://github.com/v8/v8/commit/93cd21e8254b65c15ff131b2dcadf19beadb559d
Co-authored-by: Joyee Cheung <joyeec9h3@gmail.com>
PR-URL: https://github.com/nodejs-private/node-private/pull/1008
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
This commit is contained in:
authored and Antoine du Hamel committed 2026-10-19 23:55:01 +02:00
1 parent 4b3c9bbf9f
commit fca511adc5
4 files changed
+89 -2

No files matched your search

+1 -1
View File
@@ -42,7 +42,7 @@
# Reset this number to 0 on major V8 upgrades.
# Increment by one for each non-official patch applied to deps/v8.
'v8_embedder_string': '-node.57',
'v8_embedder_string': '-node.58',
##### V8 defaults for Node.js #####
+6 -1
View File
@@ -1003,7 +1003,12 @@ class JSDataObjectBuilder {
descriptor_index)),
isolate_);
target_map = expected_final_map_;
} else {
} else if (key_chars.data() != nullptr) {
// The byte-compare transition fast path is only valid when `key_chars`
// faithfully represent the decoded key. Callers that cannot provide valid
// chars (the JSON parser passes an empty vector for escaped keys, whose raw
// source bytes differ from the decoded key) fall through to the
// decode-then-FindTransitionToField path below.
TransitionsAccessor transitions(isolate_, *map_);
auto expected_transition = transitions.ExpectedTransition(key_chars);
if (!expected_transition.first.is_null()) {
+6
View File
@@ -301,6 +301,12 @@ class JsonParser final {
JsonString ScanJsonPropertyKey(JsonContinuation* cont);
base::uc32 ScanUnicodeCharacter();
base::Vector<const Char> GetKeyChars(JsonString key) {
// For escaped keys the source range starting at `key.start()` holds the raw
// (undecoded) characters while `key.length()` is the decoded length, so the
// bytes here do not represent the actual decoded key. Return an empty
// vector to signal that the byte-compare transition fast path must be
// skipped (see JSDataObjectBuilder::TryFastTransitionToPropertyKey).
if (key.has_escape()) return base::Vector<const Char>();
return base::Vector<const Char>(chars_ + key.start(), key.length());
}
Handle<String> MakeString(const JsonString& string,
@@ -0,0 +1,76 @@
// Copyright 2026 the V8 project authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Regression test: JSON.parse must not match a hidden-class transition for an
// escaped property key using the raw (undecoded) source bytes. The builder's
// fast transition path compared `chars_ + key.start()` over `key.length()`
// (the *decoded* length), so escaped keys (e.g. "\t", "\uXXXX") collapsed to
// the byte 0x5C and matched a previously-seen "\\" key, making JSON.parse adopt
// the wrong key. Transitions are isolate-global, so a prior parse corrupted a
// later, unrelated parse.
// A single-char escaped key must keep its decoded value even after a sibling
// "\\" (backslash) key has been parsed on the same prefix map.
(function TestEscapedKeyNotRenamedByPriorBackslashKey() {
function canaryKeys() {
return Object.keys(JSON.parse('{"\\r":1,"\\f":2}'));
}
assertArrayEquals(['\r', '\f'], canaryKeys());
// Plants a {<prefix>} -> "\" transition in the global transition tree.
JSON.parse('{"\\r":3,"\\\\":4}');
// Must be unaffected: "\f" stays U+000C, not U+005C.
assertArrayEquals(['\r', '\f'], canaryKeys());
})();
// Multi-character escaped key: decoded length 2 must not be compared against
// the first two raw bytes ("\" + "r").
(function TestMultiCharEscapedKey() {
function keys() {
return Object.keys(JSON.parse('{"\\t":1,"\\r\\r":2}'));
}
assertArrayEquals(['\t', '\r\r'], keys());
JSON.parse('{"\\t":1,"\\\\r":2}'); // plants the literal "\r" (0x5C 0x72) key
assertArrayEquals(['\t', '\r\r'], keys());
})();
// \uXXXX-escaped single-character key (here decodes to plain 'A').
(function TestUnicodeEscapedKey() {
function keys() {
return Object.keys(JSON.parse('{"x":1,"\\u0041":2}'));
}
assertArrayEquals(['x', 'A'], keys());
JSON.parse('{"x":1,"\\\\":2}');
assertArrayEquals(['x', 'A'], keys());
})();
// Override/collide: an escaped key must not be renamed onto a real "\" sibling
// and silently destroy a property (key count must be preserved).
(function TestNoPropertyDestruction() {
// Prime the transition state that previously triggered the collapse.
JSON.parse('{"p":1,"\\\\":0}');
JSON.parse('{"p":1,"\\\\":0,"\\t":0}');
const o = JSON.parse('{"p":1,"\\t":"a","\\\\":"b"}');
assertEquals(3, Object.keys(o).length);
assertEquals('a', o['\t']);
assertEquals('b', o['\\']);
})();
// Self-contained single document: a later sibling object value must not be
// corrupted by an earlier one within the same parse.
(function TestNestedSiblingNotCorrupted() {
const o = JSON.parse(
'{"a":{"p":1,"\\\\":9},"b":{"p":1,"\\\\":"A","\\t":7},' +
'"c":{"p":1,"\\t":7,"\\\\":"B"}}');
assertEquals(3, Object.keys(o.c).length);
assertEquals(7, o.c['\t']);
assertEquals('B', o.c['\\']);
})();
// A plain (unescaped) empty key must still work (regression guard for the
// empty-key_chars path the fix relies on).
(function TestEmptyKeyStillWorks() {
const o = JSON.parse('{"a":1,"":2,"b":3}');
assertArrayEquals(['a', '', 'b'], Object.keys(o));
assertEquals(2, o['']);
})();