-
Notifications
You must be signed in to change notification settings - Fork 113
csslexer lockup the browser #2037
Comments
We got a customer incident for the same issue (in the context of UI5). I analysed it and think it is an example of catastrophic backtracking. The regex in the csslexer is composed of several sub-expressions, one of them for FUNCTION:
For illustration purposes, I've expanded IDENT. Then FUNCTION looks like
The combination of the repetition of Luckily, Regex: Emulate Atomic Grouping (and Possessive Quantifiers) with LookAhead describes a solution to this known issue of regular expressions. Applying the proposed pattern to the FUNCTION sub-expression seems to fix the performance problem:
Further testing is needed (e.g. whether the mandatory capturing group causes negative side-effects), and cross-browser support is a topic. The lookahead |
The caja-html-sanitizer uses a complex regular expression to tokenize CSS styles before parsing and sanitizing them. That regular expression contains a sub-expression that allows alternative interpretations of arbitrarily long input sequences and therefore might cause extensive backtracking (see googlearchive/caja#2037 ). To prevent this, the corresponding sub-expression has been rewritten to simulate an atomic group (or possessive quantifier) as described in https://instanceof.me/post/52245507631/regex-emulate-atomic-grouping-with-lookahead. Change-Id: Ia9e8e038d8b4cf5a7cf2684a14877fc08bf1be80 BCP: 002075129500001766652020
The caja-html-sanitizer uses a complex regular expression to tokenize CSS styles before parsing and sanitizing them. That regular expression contains a sub-expression that allows alternative interpretations of arbitrarily long input sequences and therefore might cause extensive backtracking (see googlearchive/caja#2037 ). To prevent this, the corresponding sub-expression has been rewritten to simulate an atomic group (or possessive quantifier) as described in https://instanceof.me/post/52245507631/regex-emulate-atomic-grouping-with-lookahead. Change-Id: Ia9e8e038d8b4cf5a7cf2684a14877fc08bf1be80 CR-Id: 002075125800001439692020 BCP: 002075129500001766652020
The caja-html-sanitizer uses a complex regular expression to tokenize CSS styles before parsing and sanitizing them. That regular expression contains a sub-expression that allows alternative interpretations of arbitrarily long input sequences and therefore might cause extensive backtracking (see googlearchive/caja#2037 ). To prevent this, the corresponding sub-expression has been rewritten to simulate an atomic group (or possessive quantifier) as described in https://instanceof.me/post/52245507631/regex-emulate-atomic-grouping-with-lookahead. Change-Id: Ia9e8e038d8b4cf5a7cf2684a14877fc08bf1be80 CR-Id: 002075125800001440612020 BCP: 002075129500001766652020
The lexCss takes too much time to perform a regex match an thus is blocking the UI.
The code snippet above is from line 239 applied to a
font-family
property.One single execution can take ~10 seconds
The text was updated successfully, but these errors were encountered: