Title: Python 3.11.0b3 chockes on regex sub from rjsmin, time grows seemingly exponentially · Issue #94675 · python/cpython · GitHub
Open Graph Title: Python 3.11.0b3 chockes on regex sub from rjsmin, time grows seemingly exponentially · Issue #94675 · python/cpython
X Title: Python 3.11.0b3 chockes on regex sub from rjsmin, time grows seemingly exponentially · Issue #94675 · python/cpython
Description: 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 fu...
Open Graph Description: 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/...
X Description: 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/ndpar...
Opengraph URL: https://github.com/python/cpython/issues/94675
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Python 3.11.0b3 chockes on regex sub from rjsmin, time grows seemingly exponentially","articleBody":"**Bug report**\r\n\r\nWhen building chromium in Fedora 37 with Python 3.11.0b3, the build hangs seemingly forever.\r\n\r\nWhile isolating the hang, we've noticed it happens in rjsmin, at https://github.com/ndparker/rjsmin/blob/1.2.0/rjsmin.py#L361\r\n\r\nI've further reduced the javascript input as much as I could \u003cdel\u003ebut I kept the regex pattern intact\u003c/del\u003e.\r\n\r\nHere's the reporucer:\r\n\r\n```python\r\nimport re, sys\r\n\r\n# pattern from rjsmin\r\n# Copyright 2011 - 2021 André Malo or his licensors, as applicable.\r\n# Apache License Version 2.0\r\n# https://github.com/ndparker/rjsmin/blob/1.2.0/rjsmin.py#L196\r\npattern = '(?\u003c=[(,=:\\\\[!\u0026|?{};\\\\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\u0026)+,.:;=?\\\\]|}-]))?'\r\n# (originally reported as) pattern = '([^\\\\047\"\\\\140/\\\\000-\\\\040]+)|((?:(?:\\\\047[^\\\\047\\\\\\\\\\\\r\\\\n]*(?:\\\\\\\\(?:[^\\\\r\\\\n]|\\\\r?\\\\n|\\\\r)[^\\\\047\\\\\\\\\\\\r\\\\n]*)*\\\\047)|(?:\"[^\"\\\\\\\\\\\\r\\\\n]*(?:\\\\\\\\(?:[^\\\\r\\\\n]|\\\\r?\\\\n|\\\\r)[^\"\\\\\\\\\\\\r\\\\n]*)*\")|(?:\\\\140[^\\\\140\\\\\\\\]*(?:\\\\\\\\(?:[^\\\\r\\\\n]|\\\\r?\\\\n|\\\\r)[^\\\\140\\\\\\\\]*)*\\\\140))[^\\\\047\"\\\\140/\\\\000-\\\\040]*)|(?\u003c=[)])(?:[\\\\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-\\\\011\\\\013\\\\014\\\\016-\\\\040]|(?:/\\\\*[^*]*\\\\*+(?:[^/*][^*]*\\\\*+)*/))*(?:(?:(?://[^\\\\r\\\\n]*)?[\\\\r\\\\n])(?:[\\\\000-\\\\011\\\\013\\\\014\\\\016-\\\\040]|(?:/\\\\*[^*]*\\\\*+(?:[^/*][^*]*\\\\*+)*/))*)*[a-z])|(?\u003c=[(,=:\\\\[!\u0026|?{};\\\\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\u0026)+,.:;=?\\\\]|}-]))?|(?\u003c=[\\\\000-#%-,./:-@\\\\[-^\\\\140{-~-]return)(?:[\\\\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\u0026)+,.:;=?\\\\]|}-]))?|(?\u003c=[^\\\\000-!#%\u0026(*,./:-@\\\\[\\\\\\\\^{|~])(?:[\\\\000-\\\\011\\\\013\\\\014\\\\016-\\\\040]|(?:/\\\\*[^*]*\\\\*+(?:[^/*][^*]*\\\\*+)*/))*(?:((?:(?://[^\\\\r\\\\n]*)?[\\\\r\\\\n]))(?:[\\\\000-\\\\011\\\\013\\\\014\\\\016-\\\\040]|(?:/\\\\*[^*]*\\\\*+(?:[^/*][^*]*\\\\*+)*/))*)+(?=[^\\\\000-\\\\040\"#%-\\\\047)*,./:-@\\\\\\\\-^\\\\140|-~])|(?\u003c=[^\\\\000-#%-,./:-@\\\\[-^\\\\140{-~-])((?:[\\\\000-\\\\011\\\\013\\\\014\\\\016-\\\\040]|(?:/\\\\*[^*]*\\\\*+(?:[^/*][^*]*\\\\*+)*/)))+(?=[^\\\\000-#%-,./:-@\\\\[-^\\\\140{-~-])|(?\u003c=\\\\+)((?:[\\\\000-\\\\011\\\\013\\\\014\\\\016-\\\\040]|(?:/\\\\*[^*]*\\\\*+(?:[^/*][^*]*\\\\*+)*/)))+(?=\\\\+)|(?\u003c=-)((?:[\\\\000-\\\\011\\\\013\\\\014\\\\016-\\\\040]|(?:/\\\\*[^*]*\\\\*+(?:[^/*][^*]*\\\\*+)*/)))+(?=-)|(?:[\\\\000-\\\\011\\\\013\\\\014\\\\016-\\\\040]|(?:/\\\\*[^*]*\\\\*+(?:[^/*][^*]*\\\\*+)*/))+|(?:(?:(?://[^\\\\r\\\\n]*)?[\\\\r\\\\n])(?:[\\\\000-\\\\011\\\\013\\\\014\\\\016-\\\\040]|(?:/\\\\*[^*]*\\\\*+(?:[^/*][^*]*\\\\*+)*/))*)+'\r\n\r\n\r\ninput_data = \"\"\"a(function() {{\r\n {}\r\n}});\r\n\"\"\".format('/' * int(sys.argv[1]))\r\n\r\nprint(re.compile(pattern).sub('', input_data))\r\n```\r\n\r\nThe original input reduced from Chromium's JavaScript file looks like:\r\n\r\n```javascript\r\na(function() {\r\n //////////////////////////////////////////////////////////////////////////\r\n}); \r\n```\r\n\r\nAnd here how long it takes with Python 3.10.5 and 3.11.0b3 for a reduced number of slashes.\r\n\r\n```\r\n$ time python3.10 reproducer.py 30\r\nreal 0m0,033s\r\n\r\n$ time python3.11 reproducer.py 30\r\nreal 0m0,082s\r\n\r\n$ time python3.10 reproducer.py 40\r\nreal 0m0,034s\r\n\r\n$ time python3.11 reproducer.py 40\r\nreal 0m6,902s\r\n\r\n$ time python3.10 reproducer.py 45\r\nreal 0m0,032s\r\n\r\n$ time python3.11 reproducer.py 45\r\nreal 1m25,004s\r\n\r\n$ time python3.10 reproducer.py 50\r\nreal 0m0,031s\r\n\r\n$ time python3.11 reproducer.py 50\r\n??? killed after 10+ minutes\r\n```\r\n\r\nFor 74 slashes, I guess it would run forever.\r\n\r\n**Your environment**\r\n\r\n\u003c!-- Include as many relevant details as possible about the environment you experienced the bug in --\u003e\r\n\r\n- CPython versions tested on: 3.11.0b3\r\n- Operating system and architecture: Fedora Linux 35 or 37, x86_64\r\n\r\n\u003c!--\r\nYou can freely edit this text. Remove any lines you believe are unnecessary.\r\n--\u003e\r\n","author":{"url":"https://github.com/hroncok","@type":"Person","name":"hroncok"},"datePublished":"2022-07-07T23:09:33.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":10},"url":"https://github.com/94675/cpython/issues/94675"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:390fa01a-3333-c74c-3c2a-662e957ba403 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | C2A2:C9E9C:131567E:1AA8988:696A3419 |
| html-safe-nonce | e162fd8fb2c73aeaa2a71594d27a8351c751de2a2ee32f2ccb4b0d6d22ca78ad |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMkEyOkM5RTlDOjEzMTU2N0U6MUFBODk4ODo2OTZBMzQxOSIsInZpc2l0b3JfaWQiOiIyNTQ2OTQ4NDI2MTQxNjc2NTY5IiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | f1253e09242f5dc460defbfbaf2001b80e1e531ce9931fb4a901acad1b809a70 |
| hovercard-subject-tag | issue:1298239560 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/94675/issue_layout |
| twitter:image | https://opengraph.githubassets.com/bfaa22d6c566c6fe59378c801b82f655a1a4a1bd43b789303f8ba86fff7b70ad/python/cpython/issues/94675 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/bfaa22d6c566c6fe59378c801b82f655a1a4a1bd43b789303f8ba86fff7b70ad/python/cpython/issues/94675 |
| og:image:alt | 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/... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | hroncok |
| hostname | github.com |
| expected-hostname | github.com |
| None | 321736bfdb3f591415ae895a0459bec204b26a76caf47ba5c980634cfacc4538 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7a9163cefd1ea4bd06f8eb7c082f43e4e53f626f |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width