⚠ Archived content — this site is no longer maintained.   Current WebKit documentation is at docs.webkit.org.

Changeset 243839 in webkit


Ignore:
Timestamp:
Apr 3, 2019, 4:51:12 PM (7 years ago)
Author:
msaboff@apple.com
Message:

REGRESSION (r243642): com.apple.JavaScriptCore crash in JSC::RegExpObject::execInline
https://bugs.webkit.org/show_bug.cgi?id=196477

Reviewed by Keith Miller.

Source/JavaScriptCore:

The problem here is that when we advance the index by 2 for a character class that only
has non-BMP characters, we might go past the end of the string. This can happen for
greedy counted character classes that are part of a alternative where there is one
character to match after the greedy non-BMP character class.

The "do we have string left to match" check at the top of the JIT loop for the counted
character class checks to see if index is not equal to the string length. For non-BMP
character classes, we need to check to see if there are at least 2 characters left.
Therefore we now temporarily add 1 to the current index before comparing. This checks
to see if there are iat least 2 characters left to match, instead of 1.

  • yarr/YarrJIT.cpp:

(JSC::Yarr::YarrGenerator::generateCharacterClassGreedy):
(JSC::Yarr::YarrGenerator::backtrackCharacterClassNonGreedy):

LayoutTests:

Updated the test with a couple more test cases to test a few variants of this bug.
Also added a couple of non-greedy counted non-BMP character class tests that don't have
the bug just to be sure.

  • js/regexp-unicode-expected.txt:
  • js/script-tests/regexp-unicode.js:
Location:
trunk
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r243828 r243839  
     12019-04-03  Michael Saboff  <msaboff@apple.com>
     2
     3        REGRESSION (r243642): com.apple.JavaScriptCore crash in JSC::RegExpObject::execInline
     4        https://bugs.webkit.org/show_bug.cgi?id=196477
     5
     6        Reviewed by Keith Miller.
     7
     8        Updated the test with a couple more test cases to test a few variants of this bug.
     9        Also added a couple of non-greedy counted non-BMP character class tests that don't have
     10        the bug just to be sure.
     11
     12        * js/regexp-unicode-expected.txt:
     13        * js/script-tests/regexp-unicode.js:
     14
    1152019-04-03  Myles C. Maxfield  <mmaxfield@apple.com>
    216
  • trunk/LayoutTests/js/regexp-unicode-expected.txt

    r221111 r243839  
    149149PASS "𐌑𐌐𐌑".match(/[𐌁𐌑]+a|[𐌐𐌑]+./iu)[0] is "𐌑𐌐𐌑"
    150150PASS "𐌑𐌐𐌑".match(/[𐌁𐌑]+?a|[𐌐𐌑]+?./iu)[0] is "𐌑𐌐"
     151PASS "𐌑𐌐𐌑".match(/[𐌁𐌑]+?a$|[𐌐𐌑]+?.$/iu)[0] is "𐌑𐌐𐌑"
     152PASS "𐌑𐌐𐌑".match(/[𐌁𐌑x]+a|[𐌐𐌑x]+./iu)[0] is "𐌑𐌐𐌑"
     153PASS "𐌑𐌐𐌑".match(/[𐌁𐌑x]+?a|[𐌐𐌑x]+?./iu)[0] is "𐌑𐌐"
    151154PASS "C83|НАЧАТЬ".match(re8)[0] is "C83|НАЧАТЬ"
    152155PASS "This.Is.16.Chars|НАЧАТЬ".match(re8)[0] is "This.Is.16.Chars|НАЧАТЬ"
  • trunk/LayoutTests/js/script-tests/regexp-unicode.js

    r221111 r243839  
    206206shouldBe('"\u{10311}\u{10310}\u{10311}".match(/[\u{10301}\u{10311}]+a|[\u{10310}\u{10311}]+./iu)[0]', '"\u{10311}\u{10310}\u{10311}"');
    207207shouldBe('"\u{10311}\u{10310}\u{10311}".match(/[\u{10301}\u{10311}]+?a|[\u{10310}\u{10311}]+?./iu)[0]', '"\u{10311}\u{10310}"');
     208shouldBe('"\u{10311}\u{10310}\u{10311}".match(/[\u{10301}\u{10311}]+?a$|[\u{10310}\u{10311}]+?.$/iu)[0]', '"\u{10311}\u{10310}\u{10311}"');
     209shouldBe('"\u{10311}\u{10310}\u{10311}".match(/[\u{10301}\u{10311}x]+a|[\u{10310}\u{10311}x]+./iu)[0]', '"\u{10311}\u{10310}\u{10311}"');
     210shouldBe('"\u{10311}\u{10310}\u{10311}".match(/[\u{10301}\u{10311}x]+?a|[\u{10310}\u{10311}x]+?./iu)[0]', '"\u{10311}\u{10310}"');
    208211
    209212var re8 = new  RegExp("^([0-9a-z\.]{3,16})\\|\u{041d}\u{0410}\u{0427}\u{0410}\u{0422}\u{042c}", "ui");
  • trunk/Source/JavaScriptCore/ChangeLog

    r243835 r243839  
     12019-04-03  Michael Saboff  <msaboff@apple.com>
     2
     3        REGRESSION (r243642): com.apple.JavaScriptCore crash in JSC::RegExpObject::execInline
     4        https://bugs.webkit.org/show_bug.cgi?id=196477
     5
     6        Reviewed by Keith Miller.
     7
     8        The problem here is that when we advance the index by 2 for a character class that only
     9        has non-BMP characters, we might go past the end of the string.  This can happen for
     10        greedy counted character classes that are part of a alternative where there is one
     11        character to match after the greedy non-BMP character class.
     12
     13        The "do we have string left to match" check at the top of the JIT loop for the counted
     14        character class checks to see if index is not equal to the string length.  For non-BMP
     15        character classes, we need to check to see if there are at least 2 characters left.
     16        Therefore we now temporarily add 1 to the current index before comparing.  This checks
     17        to see if there are iat least 2 characters left to match, instead of 1.
     18
     19        * yarr/YarrJIT.cpp:
     20        (JSC::Yarr::YarrGenerator::generateCharacterClassGreedy):
     21        (JSC::Yarr::YarrGenerator::backtrackCharacterClassNonGreedy):
     22
    1232019-04-03  Yusuke Suzuki  <ysuzuki@apple.com>
    224
  • trunk/Source/JavaScriptCore/yarr/YarrJIT.cpp

    r243642 r243839  
    18501850        JumpList failures;
    18511851        Label loop(this);
    1852         failures.append(atEndOfInput());
     1852#ifdef JIT_UNICODE_EXPRESSIONS
     1853        if (term->characterClass->hasOneCharacterSize() && !term->invert() && term->characterClass->hasNonBMPCharacters()) {
     1854            move(TrustedImm32(1), character);
     1855            failures.append(checkNotEnoughInput(character));
     1856        } else
     1857#endif
     1858            failures.append(atEndOfInput());
    18531859
    18541860        if (term->invert()) {
     
    19571963        m_backtrackingState.link(this);
    19581964
     1965#ifdef JIT_UNICODE_EXPRESSIONS
    19591966        if (m_decodeSurrogatePairs) {
    19601967            if (!term->characterClass->hasOneCharacterSize() || term->invert())
     
    19621969            loadFromFrame(term->frameLocation + BackTrackInfoCharacterClass::matchAmountIndex(), countRegister);
    19631970        }
     1971#endif
    19641972
    19651973        nonGreedyFailures.append(atEndOfInput());
Note: See TracChangeset for help on using the changeset viewer.