summaryrefslogtreecommitdiffstats
path: root/Lib/sre_parse.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-09-29 19:49:23 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2014-09-29 19:49:23 (GMT)
commit9baa5b2de2e1bd4d56791de8144f737f65b89c74 (patch)
tree59cff121a4d2becfe389a825f1e2b66e8a839c45 /Lib/sre_parse.py
parentc31e6227f94c2bb0290336c739873173672a8991 (diff)
downloadcpython-9baa5b2de2e1bd4d56791de8144f737f65b89c74.zip
cpython-9baa5b2de2e1bd4d56791de8144f737f65b89c74.tar.gz
cpython-9baa5b2de2e1bd4d56791de8144f737f65b89c74.tar.bz2
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 7fd145b..b9a1852 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")