summaryrefslogtreecommitdiff
path: root/Lib/sre_parse.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-09-29 22:49:23 +0300
committerSerhiy Storchaka <storchaka@gmail.com>2014-09-29 22:49:23 +0300
commit829b3cdf07e06cd0bd079a3080c8a85019433c1b (patch)
tree4541f61ccf1032a165ec20382cab5ccd8864f200 /Lib/sre_parse.py
parent73293efee5a03b7f349ea436d9a4b44c0a7e01e1 (diff)
downloadcpython-829b3cdf07e06cd0bd079a3080c8a85019433c1b.tar.gz
Issue #22437: Number of capturing groups in regular expression is no longer
limited by 100.
Diffstat (limited to 'Lib/sre_parse.py')
-rw-r--r--Lib/sre_parse.py10
1 files changed, 10 insertions, 0 deletions
diff --git a/Lib/sre_parse.py b/Lib/sre_parse.py
index 7fd145b623..b9a1852823 100644
--- a/Lib/sre_parse.py
+++ b/Lib/sre_parse.py
@@ -72,6 +72,8 @@ class Pattern:
def opengroup(self, name=None):
gid = self.groups
self.groups = gid + 1
+ if self.groups > MAXGROUPS:
+ raise error("groups number is too large")
if name is not None:
ogid = self.groupdict.get(name, None)
if ogid is not None:
@@ -695,8 +697,14 @@ def _parse(source, state):
else:
try:
condgroup = int(condname)
+ if condgroup < 0:
+ raise ValueError
except ValueError:
raise error("bad character in group name")
+ if not condgroup:
+ raise error("bad group number")
+ if condgroup >= MAXGROUPS:
+ raise error("the group number is too large")
else:
# flags
if not source.next in FLAGS:
@@ -822,6 +830,8 @@ def parse_template(source, pattern):
index = int(name)
if index < 0:
raise error("negative group number")
+ if index >= MAXGROUPS:
+ raise error("the group number is too large")
except ValueError:
if not name.isidentifier():
raise error("bad character in group name")