Repository navigation
Python 3.11.0b3 chockes on regex sub from rjsmin, time grows seemingly exponentially #94675
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
on Jul 7, 2022 A more "real" example is to pipe the javascript input to https://github.com/ndparker/rjsmin/blob/1.2.0/rjsmin.py
$ cat file_to_pipe_in.js a(function() { ///////////////////////////////////////////// }); $ time python3.10 rjsmin.py < file_to_pipe_in.js a(function(){}); real 0m0,039s user 0m0,031s sys 0m0,009s $ time python3.11 rjsmin.py < file_to_pipe_in.js ...I've simplified the regex to:
pattern = '(?<=[(,=:\\[!&|?{};\\r\\n+*-])(?:[\\000-\\011\\013\\014\\016-\\040]|(?:/\\*[^*]*\\*+(?:[^/*][^*]*\\*+)*/))*(?:(?:(?://[^\\r\\n]*)?[\\r\\n])(?:[\\000-\\011\\013\\014\\016-\\040]|(?:/\\*[^*]*\\*+(?:[^/*][^*]*\\*+)*/))*)*((?:/(?![\\r\\n/*])[^/\\\\\\[\\r\\n]*(?:(?:\\\\[^\\r\\n]|(?:\\[[^\\\\\\]\\r\\n]*(?:\\\\[^\\r\\n][^\\\\\\]\\r\\n]*)*\\]))[^/\\\\\\[\\r\\n]*)*/[a-z]*))((?:[\\000-\\011\\013\\014\\016-\\040]|(?:/\\*[^*]*\\*+(?:[^/*][^*]*\\*+)*/))*(?:(?:(?://[^\\r\\n]*)?[\\r\\n])(?:[\\000-\\011\\013\\014\\016-\\040]|(?:/\\*[^*]*\\*+(?:[^/*][^*]*\\*+)*/))*)+(?=[^\\000-\\040&)+,.:;=?\\]|}-]))?'
The following ones are even shorter and exhibit the same behavior but slightly different times, so I am not editing it in the original report:
pattern = r'(?<=[({}])(?:(?:(?://[^\n]*)?[\n])(?:[\000-\040])*)*((?:/[^/\[\n]*(?:(?:[^\n]|(?:\[\n]*(?:]*)*\]))[^/\[]*)*/))((?:(?:(?://[^\n]*)?[\n])(?:[\000-\040]|(?:/\*[^*]*\*+(?:[^/*]\*+)*/))*)+(?=[^\000-\040&)+,.:;=?\]|}-]))' pattern = r'(?<=[({}])(((//[^\n]*)?[\n])([\000-\040])*)*((/[^/\[\n]*(([^\n]|(\[\n]*(]*)*\]))[^/\[]*)*/))((((//[^\n]*)?[\n])([\000-\040]|(/\*[^*]*\*+([^/*]\*+)*/))*)+(?=[^\000-\040);\]}]))'- added3.11only security fixesonly security fixes3.12only security fixesonly security fixes
on Jul 8, 2022 Can you repro on latest main?
A slowdown in Chromium build was previously reported here #91404 (comment)
I believe #93928 did not make beta 3(If #93928 did indeed fix, it would be nice to add your reduced example as a test case!)
Will test.
This is fixed on main.
#93928 also fixes it on 3.11
- changed the title
[-]Python 3.11 chockes on regex sub from rjsmin, time grows seemingly exponentially[/-][+]Python 3.11.0b3 chockes on regex sub from rjsmin, time grows seemingly exponentially[/+]on Jul 8, 2022 - addedtestsTests in the Lib/test dirTests in the Lib/test dirand removed3.11only security fixesonly security fixes3.12only security fixesonly security fixes
on Jul 8, 2022 @hauntsaninja Any idea how are the "does not take too long" cases handled in cpython tests?
I've added #94685 -- hoping that the general timeout thing would stop it on b3
- added a commit that references this issue
on Jul 26, 2022 Fixed by #94685
- added a commit that references this issue
on Nov 17, 2022
Bug report
When building chromium in Fedora 37 with Python 3.11.0b3, the build hangs seemingly forever.
While isolating the hang, we've noticed it happens in rjsmin, at https://github.com/ndparker/rjsmin/blob/1.2.0/rjsmin.py#L361
I've further reduced the javascript input as much as I could
but I kept the regex pattern intact.Here's the reporucer:
The original input reduced from Chromium's JavaScript file looks like:
And here how long it takes with Python 3.10.5 and 3.11.0b3 for a reduced number of slashes.
For 74 slashes, I guess it would run forever.
Your environment