Bug 124319

Summary: Regex runtime depends on input size when it shouldn't
Product: WebKit Reporter: Peter Isza <peter.isza>
Component: JavaScriptCoreAssignee: Nobody <webkit-unassigned>
Status: NEW    
Severity: Normal CC: barraclough, msaboff, till
Priority: P3    
Version: 528+ (Nightly build)   
Hardware: All   
OS: All   
Attachments:
Description Flags
Regexp runtime tester script none

Peter Isza
Reported 2013-11-13 15:52:10 PST
Created attachment 216876 [details] Regexp runtime tester script I have run the following regular expressions on strings that contain only letter 'a': 1. /^b+/ 2. /^(b)+/ 3. /^(?:b+)/ 4. /^(?:(?:b)+)/ Obviously, there should be no matches. The regex engine should quit after reading the first character, so the running time shouldn't depend on what's after the first letter in the string. But in case #2 and #4 it does depend on it (linearly). The bug appears in Safari and Firefox (and doesn't appear in Chrome, IE and Opera). It turns out that in cases #2 and #4 YARR can't compile the expression, so it is using the interpreter. Fair enough. Then it turns out that the interpreter uses some magic backtracking algorithm instead of a finite state automaton. Alright. This magic algorithm seems to look for the matches first, and then decides whether the match is in the beginning or not: if (((matchBegin && term.anchors.m_bol) || ((matchEnd != input.end()) && term.anchors.m_eol)) && !pattern->m_multiline) return false; Could you please fix this?
Attachments
Regexp runtime tester script (626 bytes, text/html)
2013-11-13 15:52 PST, Peter Isza
no flags
Peter Isza
Comment 1 2013-11-13 15:58:38 PST
The code I pasted here isn't related, but the problem remains the same.
Note You need to log in before you can comment on or make changes to this bug.