Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
e924ddb2
Commit
e924ddb2
authored
Feb 16, 2013
by
Serhiy Storchaka
Browse files
Options
Browse Files
Download
Plain Diff
Issue #9669: Protect re against infinite loops on zero-width matching in
non-greedy repeat. Patch by Matthew Barnett.
parents
0e6b7b5c
b0c75a7d
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
19 additions
and
2 deletions
+19
-2
Lib/test/test_re.py
Lib/test/test_re.py
+9
-0
Misc/NEWS
Misc/NEWS
+3
-0
Modules/_sre.c
Modules/_sre.c
+7
-2
No files found.
Lib/test/test_re.py
View file @
e924ddb2
...
...
@@ -681,6 +681,15 @@ class ReTests(unittest.TestCase):
self.assertEqual(re.match('(x)*y', 50000*'x'+'y').group(1), 'x')
self.assertEqual(re.match('(x)*?y', 50000*'x'+'y').group(1), 'x')
def test_unlimited_zero_width_repeat(self):
# Issue #9669
self.assertIsNone(re.match(r'(?:a?)*y', 'z'))
self.assertIsNone(re.match(r'(?:a?)+y', 'z'))
self.assertIsNone(re.match(r'(?:a?){2,}y', 'z'))
self.assertIsNone(re.match(r'(?:a?)*?y', 'z'))
self.assertIsNone(re.match(r'(?:a?)+?y', 'z'))
self.assertIsNone(re.match(r'(?:a?){2,}?y', 'z'))
def test_scanner(self):
def s_ident(scanner, token): return token
def s_operator(scanner, token): return "
op
%
s
" % token
...
...
Misc/NEWS
View file @
e924ddb2
...
...
@@ -255,6 +255,9 @@ Core and Builtins
Library
-------
-
Issue
#
9669
:
Protect
re
against
infinite
loops
on
zero
-
width
matching
in
non
-
greedy
repeat
.
Patch
by
Matthew
Barnett
.
-
Issue
#
13169
:
The
maximal
repetition
number
in
a
regular
expression
has
been
increased
from
65534
to
2147483647
(
on
32
-
bit
platform
)
or
4294967294
(
on
64
-
bit
).
...
...
Modules/_sre.c
View file @
e924ddb2
...
...
@@ -1272,13 +1272,18 @@ entrance:
LASTMARK_RESTORE
();
if
(
ctx
->
count
>=
ctx
->
u
.
rep
->
pattern
[
2
]
&&
ctx
->
u
.
rep
->
pattern
[
2
]
!=
SRE_MAXREPEAT
)
if
((
ctx
->
count
>=
ctx
->
u
.
rep
->
pattern
[
2
]
&&
ctx
->
u
.
rep
->
pattern
[
2
]
!=
SRE_MAXREPEAT
)
||
state
->
ptr
==
ctx
->
u
.
rep
->
last_ptr
)
RETURN_FAILURE
;
ctx
->
u
.
rep
->
count
=
ctx
->
count
;
/* zero-width match protection */
DATA_PUSH
(
&
ctx
->
u
.
rep
->
last_ptr
);
ctx
->
u
.
rep
->
last_ptr
=
state
->
ptr
;
DO_JUMP
(
JUMP_MIN_UNTIL_3
,
jump_min_until_3
,
ctx
->
u
.
rep
->
pattern
+
3
);
DATA_POP
(
&
ctx
->
u
.
rep
->
last_ptr
);
if
(
ret
)
{
RETURN_ON_ERROR
(
ret
);
RETURN_SUCCESS
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment