diff options
author | Lysandros Nikolaou <lisandrosnik@gmail.com> | 2023-10-16 16:59:18 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-16 16:59:18 (GMT) |
commit | 3b87e520fcbe4ceb94e3a46a874a450ee9d50b01 (patch) | |
tree | 52a87cc4616bd7ebf88f50e1fdb0f88aca662082 /Lib/test/test_exceptions.py | |
parent | b8e5b1b28ac4855ce6b4d04c777fb35811a82d42 (diff) | |
download | cpython-3b87e520fcbe4ceb94e3a46a874a450ee9d50b01.zip cpython-3b87e520fcbe4ceb94e3a46a874a450ee9d50b01.tar.gz cpython-3b87e520fcbe4ceb94e3a46a874a450ee9d50b01.tar.bz2 |
[3.12] gh-107450: Check for overflow in the tokenizer and fix overflow test (GH-110832) (#110931)
(cherry picked from commit a1ac5590e0f8fe008e5562d22edab65d0c1c5507)
Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
Co-authored-by: Filipe LaĆns <lains@riseup.net>
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Lib/test/test_exceptions.py')
-rw-r--r-- | Lib/test/test_exceptions.py | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index 9de7e73..3049015 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -18,6 +18,12 @@ from test.support.os_helper import TESTFN, unlink from test.support.warnings_helper import check_warnings from test import support +try: + from _testcapi import INT_MAX +except ImportError: + INT_MAX = 2**31 - 1 + + class NaiveException(Exception): def __init__(self, x): @@ -318,11 +324,13 @@ class ExceptionTests(unittest.TestCase): check('(yield i) = 2', 1, 2) check('def f(*):\n pass', 1, 7) + @unittest.skipIf(INT_MAX >= sys.maxsize, "Downcasting to int is safe for col_offset") @support.requires_resource('cpu') - @support.bigmemtest(support._2G, memuse=1.5) - def testMemoryErrorBigSource(self, _size): - with self.assertRaises(OverflowError): - exec(f"if True:\n {' ' * 2**31}print('hello world')") + @support.bigmemtest(INT_MAX, memuse=2, dry_run=False) + def testMemoryErrorBigSource(self, size): + src = b"if True:\n%*s" % (size, b"pass") + with self.assertRaisesRegex(OverflowError, "Parser column offset overflow"): + compile(src, '<fragment>', 'exec') @cpython_only def testSettingException(self): |