Skip to content

Commit 67cd67f

Browse files
authored
Merge pull request #363 from python/bugfix/361-regexp-perf
Address potential performance weakness in EntryPoint.pattern.
2 parents 9491ef9 + 5516095 commit 67cd67f

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

CHANGES.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
v4.10.1
2+
=======
3+
4+
* #361: Avoid potential REDoS in ``EntryPoint.pattern``.
5+
16
v4.10.0
27
=======
38

exercises.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,3 +34,12 @@ def uncached_distribution_perf():
3434
# end warmup
3535
importlib.invalidate_caches()
3636
importlib_metadata.distribution('ipython')
37+
38+
39+
def entrypoint_regexp_perf():
40+
import importlib_metadata
41+
import re
42+
43+
input = '0' + ' ' * 2 ** 10 + '0' # end warmup
44+
45+
re.match(importlib_metadata.EntryPoint.pattern, input)

importlib_metadata/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,8 @@ class EntryPoint(DeprecatedTuple):
161161

162162
pattern = re.compile(
163163
r'(?P<module>[\w.]+)\s*'
164-
r'(:\s*(?P<attr>[\w.]+))?\s*'
165-
r'(?P<extras>\[.*\])?\s*$'
164+
r'(:\s*(?P<attr>[\w.]+)\s*)?'
165+
r'((?P<extras>\[.*\])\s*)?$'
166166
)
167167
"""
168168
A regular expression describing the syntax for an entry point,

0 commit comments

Comments
 (0)