]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #17998: Fix an internal error in regular expression engine.
authorSerhiy Storchaka <storchaka@gmail.com>
Sat, 3 Aug 2013 16:26:33 +0000 (19:26 +0300)
committerSerhiy Storchaka <storchaka@gmail.com>
Sat, 3 Aug 2013 16:26:33 +0000 (19:26 +0300)
Lib/test/test_re.py
Misc/NEWS
Modules/_sre.c
Modules/sre.h

index 18a81a21418bec3d42f0f44c207c5ae4fe060e8f..2be5f5cb2eabb0667575e397a3799b7e7c14bd30 100644 (file)
@@ -897,6 +897,16 @@ class ReTests(unittest.TestCase):
         with self.assertRaisesRegexp(sre_constants.error, '\?foo'):
             re.compile('(?P<?foo>)')
 
+    def test_issue17998(self):
+        for reps in '*', '+', '?', '{1}':
+            for mod in '', '?':
+                pattern = '.' + reps + mod + 'yz'
+                self.assertEqual(re.compile(pattern, re.S).findall('xyz'),
+                                 ['xyz'], msg=pattern)
+                pattern = pattern.encode()
+                self.assertEqual(re.compile(pattern, re.S).findall(b'xyz'),
+                                 [b'xyz'], msg=pattern)
+
 
 def run_re_tests():
     from test.re_tests import tests, SUCCEED, FAIL, SYNTAX_ERROR
index e3394c47fece058e3b1a5e74e26553e763db8b5b..ef614c7ce6b0daa601bceb5e64d093b701e24615 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -26,6 +26,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.
 
index 478416fb1da635d694123b36dc4e384f3763a480..c9e4f7355e9a8ed0dc8140fbc5291f4e843d4f7f 100644 (file)
@@ -1028,7 +1028,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)
+            if ((Py_ssize_t) ctx->pattern[1] > end - ctx->ptr)
                 RETURN_FAILURE; /* cannot match */
 
             state->ptr = ctx->ptr;
@@ -1111,7 +1111,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)
+            if ((Py_ssize_t) ctx->pattern[1] > end - ctx->ptr)
                 RETURN_FAILURE; /* cannot match */
 
             state->ptr = ctx->ptr;
@@ -1210,7 +1210,7 @@ entrance:
             TRACE(("|%p|%p|MAX_UNTIL %d\n", ctx->pattern,
                    ctx->ptr, ctx->count));
 
-            if (ctx->count < ctx->u.rep->pattern[1]) {
+            if (ctx->count < (Py_ssize_t) ctx->u.rep->pattern[1]) {
                 /* not enough matches */
                 ctx->u.rep->count = ctx->count;
                 DO_JUMP(JUMP_MAX_UNTIL_1, jump_max_until_1,
@@ -1224,7 +1224,7 @@ entrance:
                 RETURN_FAILURE;
             }
 
-            if ((ctx->count < ctx->u.rep->pattern[2] ||
+            if ((ctx->count < (Py_ssize_t) ctx->u.rep->pattern[2] ||
                 ctx->u.rep->pattern[2] == SRE_MAXREPEAT) &&
                 state->ptr != ctx->u.rep->last_ptr) {
                 /* we may have enough matches, but if we can
@@ -1273,7 +1273,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]) {
+            if (ctx->count < (Py_ssize_t) ctx->u.rep->pattern[1]) {
                 /* not enough matches */
                 ctx->u.rep->count = ctx->count;
                 DO_JUMP(JUMP_MIN_UNTIL_1, jump_min_until_1,
@@ -1302,7 +1302,7 @@ entrance:
 
             LASTMARK_RESTORE();
 
-            if ((ctx->count >= ctx->u.rep->pattern[2]
+            if ((ctx->count >= (Py_ssize_t) ctx->u.rep->pattern[2]
                 && ctx->u.rep->pattern[2] != SRE_MAXREPEAT) ||
                 state->ptr == ctx->u.rep->last_ptr)
                 RETURN_FAILURE;
index 15ed3d511b70f1c58481db074f7cad079a9e46fb..22a2d5dd96c4ac9dbf5bc8750ae79af1d3b36f76 100644 (file)
 # 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
 #else
 # define SRE_CODE unsigned int
 # if SIZEOF_SIZE_T > SIZEOF_INT
 #  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
 #endif