Skip to content

Commit 42e3a14

Browse files
pthieraduh95
authored andcommitted
deps: V8: backport d315af3d83cf
Original commit message: [regexp] Reset compiler flags between word boundary branches When compiling \b and \B word boundary checks in AssertionNode where the succeeding character type is unknown, two code paths (before_non_word and before_word) are generated sequentially. If the boundary assertion is placed inside a modifier group (e.g. (?i:\.|\bNULL)), emitting the first branch traverses through on_success and reaches the ActionNode that restores outer flags at group exit. This mutates flags without restoring it when returning to emit the second branch. Consequently, subsequent nodes in the second branch (before_word) were incorrectly compiled with outer flags instead of the modifier group's flags. This CL saves compiler->flags() and restores them before emitting the before_word branch in AssertionNode::EmitBoundaryCheck. TAG=agy Fixed: 544575761 Change-Id: I7f08bcb99c749d5e22636c8bd6eb44bd1d3e2e39 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/8257209 Reviewed-by: Victor Gomes <[email protected]> Commit-Queue: Patrick Thier <[email protected]> Cr-Commit-Position: refs/heads/main@{#109236} Refs: v8/v8@d315af3 Refs: nodejs#66277 PR-URL: nodejs#67207 Reviewed-by: Antoine du Hamel <[email protected]>
1 parent 9adc368 commit 42e3a14

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

‎common.gypi‎

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

4545
# Reset this number to 0 on major V8 upgrades.
4646
# Increment by one for each non-official patch applied to deps/v8.
47-
'v8_embedder_string': '-node.46',
47+
'v8_embedder_string': '-node.47',
4848

4949
##### V8 defaults for Node.js #####
5050

‎deps/v8/src/regexp/regexp-compiler.cc‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2134,6 +2134,7 @@ EmitResult AssertionNode::EmitBoundaryCheck(RegExpCompiler* compiler,
21342134
}
21352135
bool at_boundary = (assertion_type_ == AssertionNode::AT_BOUNDARY);
21362136
if (next_is_word_character == Trace::UNKNOWN) {
2137+
const RegExpFlags flags = compiler->flags();
21372138
Label before_non_word;
21382139
Label before_word;
21392140
if (trace->characters_preloaded() != 1) {
@@ -2148,6 +2149,7 @@ EmitResult AssertionNode::EmitBoundaryCheck(RegExpCompiler* compiler,
21482149
at_boundary ? kIsNonWord : kIsWord));
21492150
assembler->GoTo(&ok);
21502151

2152+
compiler->set_flags(flags);
21512153
assembler->Bind(&before_word);
21522154
RETURN_IF_ERROR(BacktrackIfPrevious(compiler, trace,
21532155
at_boundary ? kIsWord : kIsNonWord));

‎deps/v8/test/mjsunit/regexp-modifiers.js‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,16 @@ test(
8989
/^(?-i:(?:a|b)(?:c|d)(?:e|f)(?:g|h)(?:i|j)(?:k|l)(?:m|n)x)/i,
9090
['acegikmx', 'bdfhjlnx'],
9191
['acegikmX', 'bdfhjlnX']);
92+
93+
// Boundary assertions inside modifier groups with alternations must not leak
94+
// flags between branches during code generation.
95+
test(/(?i:\.|\bNULL)/, ['null', 'NULL', 'Null', '.foo'], ['xyz']);
96+
test(/(?i:\bNULL|\.)/, ['null', 'NULL', '.foo'], ['xyz']);
97+
test(/(?i:\.|\BNULL)/, ['xnull', 'xNULL'], ['null', 'xyz']);
98+
test(/(?i:\W|\bNULL)/, ['null', 'NULL', '!'], ['x']);
99+
test(/(?i:!|\?|\bNULL)/, ['null', 'NULL', '!', '?'], ['x']);
100+
test(/(?i:\.|\bnUll)/, ['null', 'NULL']);
101+
test(/(?i:\.|\bnuLl)/, ['null', 'NULL']);
102+
test(/(?i:\.|\bnulL)/, ['null', 'NULL']);
103+
test(/(?-i:(?i:\.|\bNULL))/, ['null', 'NULL', '.foo'], ['xyz']);
104+
test(/(?i:(?-i:\.|\bNULL))/, ['NULL', '.foo'], ['null', 'xyz']);

0 commit comments

Comments
 (0)