Title: [250507] branches/safari-608-branch
Revision
250507
Author
[email protected]
Date
2019-09-30 01:30:45 -0700 (Mon, 30 Sep 2019)

Log Message

Cherry-pick r249777. rdar://problem/55826876

    JSC crashes due to stack overflow while building RegExp
    https://bugs.webkit.org/show_bug.cgi?id=201649

    Reviewed by Yusuke Suzuki.

    JSTests:

    New regression test.

    * stress/regexp-bol-optimize-out-of-stack.js: Added.
    (test):
    (catch):

    Source/_javascript_Core:

    Check for running out of stack when we are optimizing RegExp containing BOL terms or
    other deep copying of disjunctions.

    * yarr/YarrPattern.cpp:
    (JSC::Yarr::YarrPatternConstructor::copyDisjunction):
    (JSC::Yarr::YarrPatternConstructor::copyTerm):
    (JSC::Yarr::YarrPatternConstructor::error):
    (JSC::Yarr::YarrPattern::compile):

    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@249777 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Modified Paths

Added Paths

Diff

Modified: branches/safari-608-branch/JSTests/ChangeLog (250506 => 250507)


--- branches/safari-608-branch/JSTests/ChangeLog	2019-09-30 08:30:43 UTC (rev 250506)
+++ branches/safari-608-branch/JSTests/ChangeLog	2019-09-30 08:30:45 UTC (rev 250507)
@@ -1,5 +1,49 @@
 2019-09-30  Babak Shafiei  <[email protected]>
 
+        Cherry-pick r249777. rdar://problem/55826876
+
+    JSC crashes due to stack overflow while building RegExp
+    https://bugs.webkit.org/show_bug.cgi?id=201649
+    
+    Reviewed by Yusuke Suzuki.
+    
+    JSTests:
+    
+    New regression test.
+    
+    * stress/regexp-bol-optimize-out-of-stack.js: Added.
+    (test):
+    (catch):
+    
+    Source/_javascript_Core:
+    
+    Check for running out of stack when we are optimizing RegExp containing BOL terms or
+    other deep copying of disjunctions.
+    
+    * yarr/YarrPattern.cpp:
+    (JSC::Yarr::YarrPatternConstructor::copyDisjunction):
+    (JSC::Yarr::YarrPatternConstructor::copyTerm):
+    (JSC::Yarr::YarrPatternConstructor::error):
+    (JSC::Yarr::YarrPattern::compile):
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@249777 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2019-09-10  Michael Saboff  <[email protected]>
+
+            JSC crashes due to stack overflow while building RegExp
+            https://bugs.webkit.org/show_bug.cgi?id=201649
+
+            Reviewed by Yusuke Suzuki.
+
+            New regression test.
+
+            * stress/regexp-bol-optimize-out-of-stack.js: Added.
+            (test):
+            (catch):
+
+2019-09-30  Babak Shafiei  <[email protected]>
+
         Cherry-pick r248951. rdar://problem/55826863
 
     [JSC] incorrent JIT lead to StackOverflow

Added: branches/safari-608-branch/JSTests/stress/regexp-bol-optimize-out-of-stack.js (0 => 250507)


--- branches/safari-608-branch/JSTests/stress/regexp-bol-optimize-out-of-stack.js	                        (rev 0)
+++ branches/safari-608-branch/JSTests/stress/regexp-bol-optimize-out-of-stack.js	2019-09-30 08:30:45 UTC (rev 250507)
@@ -0,0 +1,16 @@
+// This test that the beginning of line (bol) optimization throws when we run out of stack space.
+
+let expectedException = "SyntaxError: Invalid regular _expression_: regular _expression_ too large";
+
+function test()
+{
+    let source = Array(50000).join("(") + /(?:^|:|,)(?:\s*\[)+/g.toString() + Array(50000).join(")");
+    RegExp(source);
+}
+
+try {
+    test();
+} catch(e) {
+    if (e != expectedException)
+       throw "Expected \"" + expectedException + "\" exception, but got \"" + e + "\"";
+}

Modified: branches/safari-608-branch/Source/_javascript_Core/ChangeLog (250506 => 250507)


--- branches/safari-608-branch/Source/_javascript_Core/ChangeLog	2019-09-30 08:30:43 UTC (rev 250506)
+++ branches/safari-608-branch/Source/_javascript_Core/ChangeLog	2019-09-30 08:30:45 UTC (rev 250507)
@@ -1,5 +1,52 @@
 2019-09-30  Babak Shafiei  <[email protected]>
 
+        Cherry-pick r249777. rdar://problem/55826876
+
+    JSC crashes due to stack overflow while building RegExp
+    https://bugs.webkit.org/show_bug.cgi?id=201649
+    
+    Reviewed by Yusuke Suzuki.
+    
+    JSTests:
+    
+    New regression test.
+    
+    * stress/regexp-bol-optimize-out-of-stack.js: Added.
+    (test):
+    (catch):
+    
+    Source/_javascript_Core:
+    
+    Check for running out of stack when we are optimizing RegExp containing BOL terms or
+    other deep copying of disjunctions.
+    
+    * yarr/YarrPattern.cpp:
+    (JSC::Yarr::YarrPatternConstructor::copyDisjunction):
+    (JSC::Yarr::YarrPatternConstructor::copyTerm):
+    (JSC::Yarr::YarrPatternConstructor::error):
+    (JSC::Yarr::YarrPattern::compile):
+    
+    
+    git-svn-id: https://svn.webkit.org/repository/webkit/trunk@249777 268f45cc-cd09-0410-ab3c-d52691b4dbfc
+
+    2019-09-11  Michael Saboff  <[email protected]>
+
+            JSC crashes due to stack overflow while building RegExp
+            https://bugs.webkit.org/show_bug.cgi?id=201649
+
+            Reviewed by Yusuke Suzuki.
+
+            Check for running out of stack when we are optimizing RegExp containing BOL terms or
+            other deep copying of disjunctions.
+
+            * yarr/YarrPattern.cpp:
+            (JSC::Yarr::YarrPatternConstructor::copyDisjunction):
+            (JSC::Yarr::YarrPatternConstructor::copyTerm):
+            (JSC::Yarr::YarrPatternConstructor::error):
+            (JSC::Yarr::YarrPattern::compile):
+
+2019-09-30  Babak Shafiei  <[email protected]>
+
         Cherry-pick r248951. rdar://problem/55826863
 
     [JSC] incorrent JIT lead to StackOverflow

Modified: branches/safari-608-branch/Source/_javascript_Core/yarr/YarrPattern.cpp (250506 => 250507)


--- branches/safari-608-branch/Source/_javascript_Core/yarr/YarrPattern.cpp	2019-09-30 08:30:43 UTC (rev 250506)
+++ branches/safari-608-branch/Source/_javascript_Core/yarr/YarrPattern.cpp	2019-09-30 08:30:45 UTC (rev 250507)
@@ -702,6 +702,11 @@
     // skip alternatives with m_startsWithBOL set true.
     PatternDisjunction* copyDisjunction(PatternDisjunction* disjunction, bool filterStartsWithBOL = false)
     {
+        if (UNLIKELY(!isSafeToRecurse())) {
+            m_error = ErrorCode::PatternTooLarge;
+            return 0;
+        }
+
         std::unique_ptr<PatternDisjunction> newDisjunction;
         for (unsigned alt = 0; alt < disjunction->m_alternatives.size(); ++alt) {
             PatternAlternative* alternative = disjunction->m_alternatives[alt].get();
@@ -717,6 +722,11 @@
             }
         }
         
+        if (hasError(error())) {
+            newDisjunction = 0;
+            return 0;
+        }
+
         if (!newDisjunction)
             return 0;
 
@@ -727,6 +737,11 @@
     
     PatternTerm copyTerm(PatternTerm& term, bool filterStartsWithBOL = false)
     {
+        if (UNLIKELY(!isSafeToRecurse())) {
+            m_error = ErrorCode::PatternTooLarge;
+            return PatternTerm(term);
+        }
+
         if ((term.type != PatternTerm::TypeParenthesesSubpattern) && (term.type != PatternTerm::TypeParentheticalAssertion))
             return PatternTerm(term);
         
@@ -1100,6 +1115,8 @@
         }
     }
 
+    ErrorCode error() { return m_error; }
+
 private:
     bool isSafeToRecurse() const
     {
@@ -1116,6 +1133,7 @@
     CharacterClassConstructor m_characterClassConstructor;
     Vector<String> m_unmatchedNamedForwardReferences;
     void* m_stackLimit;
+    ErrorCode m_error { ErrorCode::NoError };
     bool m_invertCharacterClass;
     bool m_invertParentheticalAssertion { false };
 };
@@ -1151,6 +1169,9 @@
     constructor.optimizeDotStarWrappedExpressions();
     constructor.optimizeBOL();
 
+    if (hasError(constructor.error()))
+        return constructor.error();
+
     {
         ErrorCode error = constructor.setupOffsets();
         if (hasError(error))
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to