|
1 | | -from test.support import verbose, run_unittest, gc_collect, bigmemtest, _2G |
| 1 | +from test.support import verbose, run_unittest, gc_collect, bigmemtest, _2G, \ |
| 2 | + cpython_only |
2 | 3 | import io |
3 | 4 | import re |
4 | 5 | from re import Scanner |
@@ -980,6 +981,37 @@ def test_bug_16688(self): |
980 | 981 | self.assertEqual(re.findall(r"(?i)(a)\1", "aa \u0100"), ['a']) |
981 | 982 | self.assertEqual(re.match(r"(?s).{1,3}", "\u0100\u0100").span(), (0, 2)) |
982 | 983 |
|
| 984 | + def test_repeat_minmax_overflow(self): |
| 985 | + # Issue #13169 |
| 986 | + string = "x" * 100000 |
| 987 | + self.assertEqual(re.match(r".{65535}", string).span(), (0, 65535)) |
| 988 | + self.assertEqual(re.match(r".{,65535}", string).span(), (0, 65535)) |
| 989 | + self.assertEqual(re.match(r".{65535,}?", string).span(), (0, 65535)) |
| 990 | + self.assertEqual(re.match(r".{65536}", string).span(), (0, 65536)) |
| 991 | + self.assertEqual(re.match(r".{,65536}", string).span(), (0, 65536)) |
| 992 | + self.assertEqual(re.match(r".{65536,}?", string).span(), (0, 65536)) |
| 993 | + # 2**128 should be big enough to overflow both SRE_CODE and Py_ssize_t. |
| 994 | + self.assertRaises(OverflowError, re.compile, r".{%d}" % 2**128) |
| 995 | + self.assertRaises(OverflowError, re.compile, r".{,%d}" % 2**128) |
| 996 | + self.assertRaises(OverflowError, re.compile, r".{%d,}?" % 2**128) |
| 997 | + self.assertRaises(OverflowError, re.compile, r".{%d,%d}" % (2**129, 2**128)) |
| 998 | + |
| 999 | + @cpython_only |
| 1000 | + def test_repeat_minmax_overflow_maxrepeat(self): |
| 1001 | + try: |
| 1002 | + from _sre import MAXREPEAT |
| 1003 | + except ImportError: |
| 1004 | + self.skipTest('requires _sre.MAXREPEAT constant') |
| 1005 | + string = "x" * 100000 |
| 1006 | + self.assertIsNone(re.match(r".{%d}" % (MAXREPEAT - 1), string)) |
| 1007 | + self.assertEqual(re.match(r".{,%d}" % (MAXREPEAT - 1), string).span(), |
| 1008 | + (0, 100000)) |
| 1009 | + self.assertIsNone(re.match(r".{%d,}?" % (MAXREPEAT - 1), string)) |
| 1010 | + self.assertRaises(OverflowError, re.compile, r".{%d}" % MAXREPEAT) |
| 1011 | + self.assertRaises(OverflowError, re.compile, r".{,%d}" % MAXREPEAT) |
| 1012 | + self.assertRaises(OverflowError, re.compile, r".{%d,}?" % MAXREPEAT) |
| 1013 | + |
| 1014 | + |
983 | 1015 | def run_re_tests(): |
984 | 1016 | from test.re_tests import tests, SUCCEED, FAIL, SYNTAX_ERROR |
985 | 1017 | if verbose: |
|
0 commit comments