Ignore:
Timestamp:
Oct 20, 2015, 4:38:41 PM (10 years ago)
Author:
[email protected]
Message:

YarrPatternConstructor::containsCapturingTerms() should not assume that its terms.size() is greater than 0.
https://bugs.webkit.org/show_bug.cgi?id=150372

Reviewed by Geoffrey Garen.

Source/JavaScriptCore:

  • yarr/YarrPattern.cpp:

(JSC::Yarr::CharacterClassConstructor::CharacterClassConstructor):
(JSC::Yarr::YarrPatternConstructor::optimizeBOL):
(JSC::Yarr::YarrPatternConstructor::containsCapturingTerms):
(JSC::Yarr::YarrPatternConstructor::optimizeDotStarWrappedExpressions):

LayoutTests:

  • js/regress-150372-expected.txt: Added.
  • js/regress-150372.html: Added.
  • js/script-tests/regress-150372.js: Added.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/JavaScriptCore/yarr/YarrPattern.cpp

    r177820 r191364  
    740740    }
    741741
    742     bool containsCapturingTerms(PatternAlternative* alternative, size_t firstTermIndex, size_t lastTermIndex)
     742    bool containsCapturingTerms(PatternAlternative* alternative, size_t firstTermIndex, size_t endIndex)
    743743    {
    744744        Vector<PatternTerm>& terms = alternative->m_terms;
    745745
    746         for (size_t termIndex = firstTermIndex; termIndex <= lastTermIndex; ++termIndex) {
     746        ASSERT(endIndex <= terms.size());
     747        for (size_t termIndex = firstTermIndex; termIndex < endIndex; ++termIndex) {
    747748            PatternTerm& term = terms[termIndex];
    748749
     
    753754                PatternDisjunction* nestedDisjunction = term.parentheses.disjunction;
    754755                for (unsigned alt = 0; alt < nestedDisjunction->m_alternatives.size(); ++alt) {
    755                     if (containsCapturingTerms(nestedDisjunction->m_alternatives[alt].get(), 0, nestedDisjunction->m_alternatives[alt]->m_terms.size() - 1))
     756                    if (containsCapturingTerms(nestedDisjunction->m_alternatives[alt].get(), 0, nestedDisjunction->m_alternatives[alt]->m_terms.size()))
    756757                        return true;
    757758                }
     
    778779            bool startsWithBOL = false;
    779780            bool endsWithEOL = false;
    780             size_t termIndex, firstExpressionTerm, lastExpressionTerm;
     781            size_t termIndex, firstExpressionTerm;
    781782
    782783            termIndex = 0;
     
    801802            if ((lastNonAnchorTerm.type != PatternTerm::TypeCharacterClass) || (lastNonAnchorTerm.characterClass != m_pattern.newlineCharacterClass()) || (lastNonAnchorTerm.quantityType != QuantifierGreedy))
    802803                return;
    803            
    804             lastExpressionTerm = termIndex - 1;
    805 
    806             if (firstExpressionTerm > lastExpressionTerm)
     804
     805            size_t endIndex = termIndex;
     806            if (firstExpressionTerm >= endIndex)
    807807                return;
    808808
    809             if (!containsCapturingTerms(alternative, firstExpressionTerm, lastExpressionTerm)) {
    810                 for (termIndex = terms.size() - 1; termIndex > lastExpressionTerm; --termIndex)
     809            if (!containsCapturingTerms(alternative, firstExpressionTerm, endIndex)) {
     810                for (termIndex = terms.size() - 1; termIndex >= endIndex; --termIndex)
    811811                    terms.remove(termIndex);
    812812
Note: See TracChangeset for help on using the changeset viewer.