Skip to content

Commit b469772

Browse files
hashseedCommit bot
authored andcommitted
MIPS64: [regexp] do not assume short external strings have a minimum size.
Port 3518e49 Original commit message: Short external strings do not cache the resource data, and may be used for compressible strings. The assumptions about their lengths is invalid and may lead to oob reads. [email protected] BUG=v8:4923,chromium:604897 LOG=N Review URL: https://codereview.chromium.org/1902393004 Cr-Commit-Position: refs/heads/master@{#35683}
1 parent 14c9cbd commit b469772

2 files changed

Lines changed: 37 additions & 42 deletions

File tree

src/mips64/code-stubs-mips64.cc

Lines changed: 37 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1685,48 +1685,53 @@ void RegExpExecStub::Generate(MacroAssembler* masm) {
16851685
__ mov(a3, subject); // Make a copy of the original subject string.
16861686
__ ld(a0, FieldMemOperand(subject, HeapObject::kMapOffset));
16871687
__ lbu(a0, FieldMemOperand(a0, Map::kInstanceTypeOffset));
1688+
16881689
// subject: subject string
1689-
// a3: subject string
16901690
// a0: subject string instance type
1691+
// a3: subject string
16911692
// regexp_data: RegExp data (FixedArray)
16921693
// Handle subject string according to its encoding and representation:
1693-
// (1) Sequential string? If yes, go to (5).
1694-
// (2) Anything but sequential or cons? If yes, go to (6).
1695-
// (3) Cons string. If the string is flat, replace subject with first string.
1696-
// Otherwise bailout.
1697-
// (4) Is subject external? If yes, go to (7).
1698-
// (5) Sequential string. Load regexp code according to encoding.
1694+
// (1) Sequential string? If yes, go to (4).
1695+
// (2) Sequential or cons? If not, go to (5).
1696+
// (3) Cons string. If the string is flat, replace subject with first string
1697+
// and go to (1). Otherwise bail out to runtime.
1698+
// (4) Sequential string. Load regexp code according to encoding.
16991699
// (E) Carry on.
17001700
/// [...]
17011701

17021702
// Deferred code at the end of the stub:
1703-
// (6) Not a long external string? If yes, go to (8).
1704-
// (7) External string. Make it, offset-wise, look like a sequential string.
1705-
// Go to (5).
1706-
// (8) Short external string or not a string? If yes, bail out to runtime.
1707-
// (9) Sliced string. Replace subject with parent. Go to (4).
1708-
1709-
Label check_underlying; // (4)
1710-
Label seq_string; // (5)
1711-
Label not_seq_nor_cons; // (6)
1712-
Label external_string; // (7)
1713-
Label not_long_external; // (8)
1714-
1715-
// (1) Sequential string? If yes, go to (5).
1703+
// (5) Long external string? If not, go to (7).
1704+
// (6) External string. Make it, offset-wise, look like a sequential string.
1705+
// Go to (4).
1706+
// (7) Short external string or not a string? If yes, bail out to runtime.
1707+
// (8) Sliced string. Replace subject with parent. Go to (1).
1708+
1709+
Label check_underlying; // (1)
1710+
Label seq_string; // (4)
1711+
Label not_seq_nor_cons; // (5)
1712+
Label external_string; // (6)
1713+
Label not_long_external; // (7)
1714+
1715+
__ bind(&check_underlying);
1716+
__ ld(a2, FieldMemOperand(subject, HeapObject::kMapOffset));
1717+
__ Daddu(a0, a2, Map::kInstanceTypeOffset);
1718+
__ lbu(a0, MemOperand(a0));
1719+
1720+
// (1) Sequential string? If yes, go to (4).
17161721
__ And(a1,
17171722
a0,
17181723
Operand(kIsNotStringMask |
17191724
kStringRepresentationMask |
17201725
kShortExternalStringMask));
17211726
STATIC_ASSERT((kStringTag | kSeqStringTag) == 0);
1722-
__ Branch(&seq_string, eq, a1, Operand(zero_reg)); // Go to (5).
1727+
__ Branch(&seq_string, eq, a1, Operand(zero_reg)); // Go to (4).
17231728

1724-
// (2) Anything but sequential or cons? If yes, go to (6).
1729+
// (2) Sequential or cons? If not, go to (5).
17251730
STATIC_ASSERT(kConsStringTag < kExternalStringTag);
17261731
STATIC_ASSERT(kSlicedStringTag > kExternalStringTag);
17271732
STATIC_ASSERT(kIsNotStringMask > kExternalStringTag);
17281733
STATIC_ASSERT(kShortExternalStringTag > kExternalStringTag);
1729-
// Go to (6).
1734+
// Go to (5).
17301735
__ Branch(&not_seq_nor_cons, ge, a1, Operand(kExternalStringTag));
17311736

17321737
// (3) Cons string. Check that it's flat.
@@ -1735,16 +1740,9 @@ void RegExpExecStub::Generate(MacroAssembler* masm) {
17351740
__ LoadRoot(a1, Heap::kempty_stringRootIndex);
17361741
__ Branch(&runtime, ne, a0, Operand(a1));
17371742
__ ld(subject, FieldMemOperand(subject, ConsString::kFirstOffset));
1743+
__ jmp(&check_underlying);
17381744

1739-
// (4) Is subject external? If yes, go to (7).
1740-
__ bind(&check_underlying);
1741-
__ ld(a0, FieldMemOperand(subject, HeapObject::kMapOffset));
1742-
__ lbu(a0, FieldMemOperand(a0, Map::kInstanceTypeOffset));
1743-
STATIC_ASSERT(kSeqStringTag == 0);
1744-
__ And(at, a0, Operand(kStringRepresentationMask));
1745-
__ Branch(&external_string, ne, at, Operand(zero_reg)); // Go to (7).
1746-
1747-
// (5) Sequential string. Load regexp code according to encoding.
1745+
// (4) Sequential string. Load regexp code according to encoding.
17481746
__ bind(&seq_string);
17491747
// subject: sequential subject string (or look-alike, external string)
17501748
// a3: original subject string
@@ -1987,12 +1985,12 @@ void RegExpExecStub::Generate(MacroAssembler* masm) {
19871985
__ TailCallRuntime(Runtime::kRegExpExec);
19881986

19891987
// Deferred code for string handling.
1990-
// (6) Not a long external string? If yes, go to (8).
1988+
// (5) Long external string? If not, go to (7).
19911989
__ bind(&not_seq_nor_cons);
1992-
// Go to (8).
1990+
// Go to (7).
19931991
__ Branch(&not_long_external, gt, a1, Operand(kExternalStringTag));
19941992

1995-
// (7) External string. Make it, offset-wise, look like a sequential string.
1993+
// (6) External string. Make it, offset-wise, look like a sequential string.
19961994
__ bind(&external_string);
19971995
__ ld(a0, FieldMemOperand(subject, HeapObject::kMapOffset));
19981996
__ lbu(a0, FieldMemOperand(a0, Map::kInstanceTypeOffset));
@@ -2012,20 +2010,20 @@ void RegExpExecStub::Generate(MacroAssembler* masm) {
20122010
__ Dsubu(subject,
20132011
subject,
20142012
SeqTwoByteString::kHeaderSize - kHeapObjectTag);
2015-
__ jmp(&seq_string); // Go to (5).
2013+
__ jmp(&seq_string); // Go to (4).
20162014

2017-
// (8) Short external string or not a string? If yes, bail out to runtime.
2015+
// (7) Short external string or not a string? If yes, bail out to runtime.
20182016
__ bind(&not_long_external);
20192017
STATIC_ASSERT(kNotStringTag != 0 && kShortExternalStringTag !=0);
20202018
__ And(at, a1, Operand(kIsNotStringMask | kShortExternalStringMask));
20212019
__ Branch(&runtime, ne, at, Operand(zero_reg));
20222020

2023-
// (9) Sliced string. Replace subject with parent. Go to (4).
2021+
// (8) Sliced string. Replace subject with parent. Go to (4).
20242022
// Load offset into t0 and replace subject string with parent.
20252023
__ ld(t0, FieldMemOperand(subject, SlicedString::kOffsetOffset));
20262024
__ SmiUntag(t0);
20272025
__ ld(subject, FieldMemOperand(subject, SlicedString::kParentOffset));
2028-
__ jmp(&check_underlying); // Go to (4).
2026+
__ jmp(&check_underlying); // Go to (1).
20292027
#endif // V8_INTERPRETED_REGEXP
20302028
}
20312029

test/cctest/cctest.status

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,6 @@
8686
'test-func-name-inference/UpperCaseClass': [FAIL],
8787
'test-func-name-inference/LowerCaseClass': [FAIL],
8888

89-
# BUG(4923). MIPS64 port is missing.
90-
'test-regexp/UncachedExternalString': [PASS, ['arch==mips64 or arch==mips64el', FAIL]],
91-
9289
##############################################################################
9390
# TurboFan compiler failures.
9491

0 commit comments

Comments
 (0)