Changeset 242838 in webkit


Ignore:
Timestamp:
Mar 12, 2019 6:26:29 PM (5 years ago)
Author:
msaboff@apple.com
Message:

REGRESSION (iOS 12.2): Webpage using CoffeeScript crashes
https://bugs.webkit.org/show_bug.cgi?id=195613

Reviewed by Mark Lam.

JSTests:

New regression test.

  • stress/regexp-backref-inbounds.js: Added.

(testRegExp):

Source/JavaScriptCore:

The bug here is in Yarr JIT backreference matching code. We are incorrectly
using a checkedOffset / inputPosition correction when checking for the available
length left in a string. It is improper to do these corrections as a backreference's
match length is based on what was matched in the referenced capture group and not
part of the checkedOffset and inputPosition computed when we compiled the RegExp.
In some cases, the resulting incorrect calculation would allow us to go past
the subject string's length. Removed these adjustments.

After writing tests for the first bug, found another bug where the non-greedy
backreference backtracking code didn't do an "are we at the end of the input?" check.
This caused an infinite loop as we'd jump from the backtracking code back to
try matching one more backreference, fail and then backtrack.

  • yarr/YarrJIT.cpp:

(JSC::Yarr::YarrGenerator::generateBackReference):
(JSC::Yarr::YarrGenerator::backtrackBackReference):

Location:
trunk
Files:
1 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/JSTests/ChangeLog

    r242810 r242838  
     12019-03-12  Michael Saboff  <msaboff@apple.com>
     2
     3        REGRESSION (iOS 12.2): Webpage using CoffeeScript crashes
     4        https://bugs.webkit.org/show_bug.cgi?id=195613
     5
     6        Reviewed by Mark Lam.
     7
     8        New regression test.
     9
     10        * stress/regexp-backref-inbounds.js: Added.
     11        (testRegExp):
     12
    1132019-03-12  Mark Lam  <mark.lam@apple.com>
    214
  • trunk/Source/JavaScriptCore/ChangeLog

    r242812 r242838  
     12019-03-12  Michael Saboff  <msaboff@apple.com>
     2
     3        REGRESSION (iOS 12.2): Webpage using CoffeeScript crashes
     4        https://bugs.webkit.org/show_bug.cgi?id=195613
     5
     6        Reviewed by Mark Lam.
     7
     8        The bug here is in Yarr JIT backreference matching code.  We are incorrectly
     9        using a checkedOffset / inputPosition correction when checking for the available
     10        length left in a string.  It is improper to do these corrections as a backreference's
     11        match length is based on what was matched in the referenced capture group and not
     12        part of the checkedOffset and inputPosition computed when we compiled the RegExp.
     13        In some cases, the resulting incorrect calculation would allow us to go past
     14        the subject string's length.  Removed these adjustments.
     15
     16        After writing tests for the first bug, found another bug where the non-greedy
     17        backreference backtracking code didn't do an "are we at the end of the input?" check.
     18        This caused an infinite loop as we'd jump from the backtracking code back to
     19        try matching one more backreference, fail and then backtrack.
     20
     21        * yarr/YarrJIT.cpp:
     22        (JSC::Yarr::YarrGenerator::generateBackReference):
     23        (JSC::Yarr::YarrGenerator::backtrackBackReference):
     24
    1252019-03-12  Robin Morisset  <rmorisset@apple.com>
    226
  • trunk/Source/JavaScriptCore/yarr/YarrJIT.cpp

    r241634 r242838  
    11991199            // PatternTemp should contain pattern end index at this point
    12001200            sub32(patternIndex, patternTemp);
    1201             if (m_checkedOffset - term->inputPosition)
    1202                 sub32(Imm32((m_checkedOffset - term->inputPosition).unsafeGet()), patternTemp);
    12031201            op.m_jumps.append(checkNotEnoughInput(patternTemp));
    12041202
     
    12251223            // PatternTemp should contain pattern end index at this point
    12261224            sub32(patternIndex, patternTemp);
    1227             if (m_checkedOffset - term->inputPosition)
    1228                 sub32(Imm32((m_checkedOffset - term->inputPosition).unsafeGet()), patternTemp);
    12291225            matches.append(checkNotEnoughInput(patternTemp));
    12301226
     
    12711267            // Check if we have input remaining to match
    12721268            sub32(patternIndex, patternTemp);
    1273             if (m_checkedOffset - term->inputPosition)
    1274                 sub32(Imm32((m_checkedOffset - term->inputPosition).unsafeGet()), patternTemp);
    12751269            matches.append(checkNotEnoughInput(patternTemp));
    12761270
     
    13291323            const RegisterID matchAmount = regT0;
    13301324
     1325            failures.append(atEndOfInput());
    13311326            loadFromFrame(parenthesesFrameLocation + BackTrackInfoBackReference::matchAmountIndex(), matchAmount);
    13321327            if (term->quantityMaxCount != quantifyInfinite)
Note: See TracChangeset for help on using the changeset viewer.