Skip to content

Commit

Permalink
Merge pull request #363 from python/bugfix/361-regexp-perf
Browse files Browse the repository at this point in the history
Address potential performance weakness in EntryPoint.pattern.
  • Loading branch information
jaraco committed Jan 17, 2022
2 parents 9491ef9 + 5516095 commit 67cd67f
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
v4.10.1
=======

* #361: Avoid potential REDoS in ``EntryPoint.pattern``.

v4.10.0
=======

Expand Down
9 changes: 9 additions & 0 deletions exercises.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,12 @@ def uncached_distribution_perf():
# end warmup
importlib.invalidate_caches()
importlib_metadata.distribution('ipython')


def entrypoint_regexp_perf():
import importlib_metadata
import re

input = '0' + ' ' * 2 ** 10 + '0' # end warmup

re.match(importlib_metadata.EntryPoint.pattern, input)
4 changes: 2 additions & 2 deletions importlib_metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ class EntryPoint(DeprecatedTuple):

pattern = re.compile(
r'(?P<module>[\w.]+)\s*'
r'(:\s*(?P<attr>[\w.]+))?\s*'
r'(?P<extras>\[.*\])?\s*$'
r'(:\s*(?P<attr>[\w.]+)\s*)?'
r'((?P<extras>\[.*\])\s*)?$'
)
"""
A regular expression describing the syntax for an entry point,
Expand Down

0 comments on commit 67cd67f

Please sign in to comment.