deps: V8: backport 93cd21e8254b · nodejs/node@fca511a · GitHub
Skip to content

Commit fca511a

Browse files
joyeecheungaduh95
authored andcommitted
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: v8/v8@93cd21e Co-authored-by: Joyee Cheung <joyeec9h3@gmail.com> PR-URL: nodejs-private/node-private#1008 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 4b3c9bb commit fca511a

4 files changed

Lines changed: 89 additions & 2 deletions

File tree

‎common.gypi‎

Lines changed: 1 addition & 1 deletion

‎deps/v8/src/json/json-parser.cc‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,12 @@ class JSDataObjectBuilder {
10031003
descriptor_index)),
10041004
isolate_);
10051005
target_map = expected_final_map_;
1006-
} else {
1006+
} else if (key_chars.data() != nullptr) {
1007+
// The byte-compare transition fast path is only valid when `key_chars`
1008+
// faithfully represent the decoded key. Callers that cannot provide valid
1009+
// chars (the JSON parser passes an empty vector for escaped keys, whose raw
1010+
// source bytes differ from the decoded key) fall through to the
1011+
// decode-then-FindTransitionToField path below.
10071012
TransitionsAccessor transitions(isolate_, *map_);
10081013
auto expected_transition = transitions.ExpectedTransition(key_chars);
10091014
if (!expected_transition.first.is_null()) {

‎deps/v8/src/json/json-parser.h‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,12 @@ class JsonParser final {
301301
JsonString ScanJsonPropertyKey(JsonContinuation* cont);
302302
base::uc32 ScanUnicodeCharacter();
303303
base::Vector<const Char> GetKeyChars(JsonString key) {
304+
// For escaped keys the source range starting at `key.start()` holds the raw
305+
// (undecoded) characters while `key.length()` is the decoded length, so the
306+
// bytes here do not represent the actual decoded key. Return an empty
307+
// vector to signal that the byte-compare transition fast path must be
308+
// skipped (see JSDataObjectBuilder::TryFastTransitionToPropertyKey).
309+
if (key.has_escape()) return base::Vector<const Char>();
304310
return base::Vector<const Char>(chars_ + key.start(), key.length());
305311
}
306312
Handle<String> MakeString(const JsonString& string,
Lines changed: 76 additions & 0 deletions

0 commit comments

Comments
 (0)