From: Serhiy Storchaka Date: Sat, 16 Feb 2013 14:54:33 +0000 (+0200) Subject: Issue #13169: The maximal repetition number in a regular expression has been X-Git-Tag: v3.3.1rc1~170 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a0eb80999538febe046164bae541d3f07b899dfb;p=python 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). --- a0eb80999538febe046164bae541d3f07b899dfb diff --cc Lib/test/test_re.py index feae7c5507,f7e76dcfba..9346f8b5ea --- a/Lib/test/test_re.py +++ b/Lib/test/test_re.py @@@ -974,12 -883,38 +975,43 @@@ class ReTests(unittest.TestCase) self.assertEqual(r, s) self.assertEqual(n, size + 1) + def test_bug_16688(self): + # Issue 16688: Backreferences make case-insensitive regex fail on + # non-ASCII strings. + self.assertEqual(re.findall(r"(?i)(a)\1", "aa \u0100"), ['a']) + self.assertEqual(re.match(r"(?s).{1,3}", "\u0100\u0100").span(), (0, 2)) + def test_repeat_minmax_overflow(self): + # Issue #13169 + string = "x" * 100000 + self.assertEqual(re.match(r".{65535}", string).span(), (0, 65535)) + self.assertEqual(re.match(r".{,65535}", string).span(), (0, 65535)) + self.assertEqual(re.match(r".{65535,}?", string).span(), (0, 65535)) + self.assertEqual(re.match(r".{65536}", string).span(), (0, 65536)) + self.assertEqual(re.match(r".{,65536}", string).span(), (0, 65536)) + self.assertEqual(re.match(r".{65536,}?", string).span(), (0, 65536)) + # 2**128 should be big enough to overflow both SRE_CODE and Py_ssize_t. + self.assertRaises(OverflowError, re.compile, r".{%d}" % 2**128) + self.assertRaises(OverflowError, re.compile, r".{,%d}" % 2**128) + self.assertRaises(OverflowError, re.compile, r".{%d,}?" % 2**128) + self.assertRaises(OverflowError, re.compile, r".{%d,%d}" % (2**129, 2**128)) + + @cpython_only + def test_repeat_minmax_overflow_maxrepeat(self): + try: + from _sre import MAXREPEAT + except ImportError: + self.skipTest('requires _sre.MAXREPEAT constant') + string = "x" * 100000 + self.assertIsNone(re.match(r".{%d}" % (MAXREPEAT - 1), string)) + self.assertEqual(re.match(r".{,%d}" % (MAXREPEAT - 1), string).span(), + (0, 100000)) + self.assertIsNone(re.match(r".{%d,}?" % (MAXREPEAT - 1), string)) + self.assertRaises(OverflowError, re.compile, r".{%d}" % MAXREPEAT) + self.assertRaises(OverflowError, re.compile, r".{,%d}" % MAXREPEAT) + self.assertRaises(OverflowError, re.compile, r".{%d,}?" % MAXREPEAT) + + def run_re_tests(): from test.re_tests import tests, SUCCEED, FAIL, SYNTAX_ERROR if verbose: diff --cc Misc/NEWS index ba2188637f,83405c424b..0abe0e7b5c --- a/Misc/NEWS +++ b/Misc/NEWS @@@ -178,9 -224,10 +178,13 @@@ Core and Builtin Library ------- + - 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). + +- Issue #17143: Fix a missing import in the trace module. Initial patch by + Berker Peksag. + - Issue #16743: Fix mmap overflow check on 32 bit Windows. - Issue #16800: tempfile.gettempdir() no longer left temporary files when diff --cc Modules/_sre.c index aa56529f90,4421eae83a..c3c983d968 --- a/Modules/_sre.c +++ b/Modules/_sre.c @@@ -492,8 -517,8 +492,8 @@@ SRE_COUNT(SRE_STATE* state, SRE_CODE* p Py_ssize_t i; /* adjust end */ - if (maxcount < (end - ptr) / state->charsize && maxcount != 65535) - if (maxcount < end - ptr && maxcount != SRE_MAXREPEAT) - end = ptr + maxcount; ++ if (maxcount < (end - ptr) / state->charsize && maxcount != SRE_MAXREPEAT) + end = ptr + maxcount*state->charsize; switch (pattern[0]) {