cpython: 86b8b035529b (original) (raw)
Mercurial > cpython
changeset 84989:86b8b035529b 3.3
Issue #17998: Fix an internal error in regular expression engine. [#17998]
Serhiy Storchaka storchaka@gmail.com | |
---|---|
date | Sat, 03 Aug 2013 19🔞38 +0300 |
parents | c503cea0e8c2 |
children | 36702442ffe0 797b1d13d16e ecc8512b427d |
files | Lib/test/test_re.py Misc/NEWS Modules/_sre.c Modules/sre.h |
diffstat | 4 files changed, 19 insertions(+), 7 deletions(-)[+] [-] Lib/test/test_re.py 10 Misc/NEWS 2 Modules/_sre.c 12 Modules/sre.h 2 |
line wrap: on
line diff
--- a/Lib/test/test_re.py +++ b/Lib/test/test_re.py @@ -1040,6 +1040,16 @@ class ReTests(unittest.TestCase): with self.assertRaisesRegex(sre_constants.error, '?foo'): re.compile('(?P<?foo>)')
- def test_issue17998(self):
for reps in '*', '+', '?', '{1}':[](#l1.8)
for mod in '', '?':[](#l1.9)
pattern = '.' + reps + mod + 'yz'[](#l1.10)
self.assertEqual(re.compile(pattern, re.S).findall('xyz'),[](#l1.11)
['xyz'], msg=pattern)[](#l1.12)
pattern = pattern.encode()[](#l1.13)
self.assertEqual(re.compile(pattern, re.S).findall(b'xyz'),[](#l1.14)
[b'xyz'], msg=pattern)[](#l1.15)
+ def run_re_tests(): from test.re_tests import tests, SUCCEED, FAIL, SYNTAX_ERROR
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -59,6 +59,8 @@ Core and Builtins Library ------- +- Issue #17998: Fix an internal error in regular expression engine. +
- Issue #17557: Fix os.getgroups() to work with the modified behavior of getgroups(2) on OS X 10.8. Original patch by Mateusz Lenik.
--- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -997,7 +997,7 @@ entrance: TRACE(("|%p|%p|REPEAT_ONE %d %d\n", ctx->pattern, ctx->ptr, ctx->pattern[1], ctx->pattern[2]));
if (ctx->pattern[1] > (end - ctx->ptr) / state->charsize)[](#l3.7)
if ((Py_ssize_t) ctx->pattern[1] > (end - ctx->ptr) / state->charsize)[](#l3.8) RETURN_FAILURE; /* cannot match */[](#l3.9)
state->ptr = ctx->ptr; @@ -1081,7 +1081,7 @@ entrance: TRACE(("|%p|%p|MIN_REPEAT_ONE %d %d\n", ctx->pattern, ctx->ptr, ctx->pattern[1], ctx->pattern[2]));
if (ctx->pattern[1] > (end - ctx->ptr) / state->charsize)[](#l3.16)
if ((Py_ssize_t) ctx->pattern[1] > (end - ctx->ptr) / state->charsize)[](#l3.17) RETURN_FAILURE; /* cannot match */[](#l3.18)
state->ptr = ctx->ptr; @@ -1180,7 +1180,7 @@ entrance: TRACE(("|%p|%p|MAX_UNTIL %d\n", ctx->pattern, ctx->ptr, ctx->count));
if (ctx->count < ctx->u.rep->pattern[1]) {[](#l3.25)
if (ctx->count < (Py_ssize_t) ctx->u.rep->pattern[1]) {[](#l3.26) /* not enough matches */[](#l3.27) ctx->u.rep->count = ctx->count;[](#l3.28) DO_JUMP(JUMP_MAX_UNTIL_1, jump_max_until_1,[](#l3.29)
@@ -1194,7 +1194,7 @@ entrance: RETURN_FAILURE; }
if ((ctx->count < ctx->u.rep->pattern[2] ||[](#l3.34)
if ((ctx->count < (Py_ssize_t) ctx->u.rep->pattern[2] ||[](#l3.35) ctx->u.rep->pattern[2] == SRE_MAXREPEAT) &&[](#l3.36) state->ptr != ctx->u.rep->last_ptr) {[](#l3.37) /* we may have enough matches, but if we can[](#l3.38)
@@ -1243,7 +1243,7 @@ entrance: TRACE(("|%p|%p|MIN_UNTIL %d %p\n", ctx->pattern, ctx->ptr, ctx->count, ctx->u.rep->pattern));
if (ctx->count < ctx->u.rep->pattern[1]) {[](#l3.43)
if (ctx->count < (Py_ssize_t) ctx->u.rep->pattern[1]) {[](#l3.44) /* not enough matches */[](#l3.45) ctx->u.rep->count = ctx->count;[](#l3.46) DO_JUMP(JUMP_MIN_UNTIL_1, jump_min_until_1,[](#l3.47)
@@ -1272,7 +1272,7 @@ entrance: LASTMARK_RESTORE();
if ((ctx->count >= ctx->u.rep->pattern[2][](#l3.52)
if ((ctx->count >= (Py_ssize_t) ctx->u.rep->pattern[2][](#l3.53) && ctx->u.rep->pattern[2] != SRE_MAXREPEAT) ||[](#l3.54) state->ptr == ctx->u.rep->last_ptr)[](#l3.55) RETURN_FAILURE;[](#l3.56)
--- a/Modules/sre.h +++ b/Modules/sre.h @@ -19,7 +19,7 @@ #if SIZEOF_SIZE_T > 4
define SRE_MAXREPEAT (~(SRE_CODE)0)
#else -# define SRE_MAXREPEAT ((SRE_CODE)PY_SSIZE_T_MAX + 1u) +# define SRE_MAXREPEAT ((SRE_CODE)PY_SSIZE_T_MAX) #endif typedef struct {