paulk-asert opened a new pull request, #2809:
URL: https://github.com/apache/groovy/pull/2809

   JsonLexer's string branch appended one character at a time and, at every 
unescaped quote, re-validated the whole accumulated token by copying it to a 
String and running two regular expressions over it. For a well formed string 
the closing quote is the first unescaped one, so that happened once. For a 
string holding an invalid escape the validation could never succeed, so the 
loop consumed the rest of the document and paid the cost again at every quote 
it passed, giving O(n^2) behaviour on input an author controls.
   
   Measured on a document of the shape {"k":"\q" followed by n quotes, parsed 
with JsonSlurperClassic:
   
     quotes    before     after
      2,000     42 ms      4 ms
      4,000     67 ms      0 ms
      8,000    220 ms      0 ms
     16,000    874 ms      0 ms
   
   Read and check each escape sequence where the backslash is found instead. 
The scan becomes linear, the accepted language is unchanged, and a bad escape 
is now reported at its own position rather than after the document has been 
consumed to its end. Escape-state tracking is no longer needed, since consuming 
the sequence in place is what distinguishes an escaped quote from a closing one.
   
   Note the reach is wider than the parser: JsonOutput.prettyPrint(String) 
lexes through the same class, so it shared the behaviour.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to