Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Simplify test
  • Loading branch information
tomasr8 committed Oct 6, 2024
commit a44751144ef4debeab39a96607a38ff6b041fe4f
18 changes: 7 additions & 11 deletions Lib/test/test_ast/test_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,13 @@ def test_repr(self) -> None:
with self.subTest(test_input=test):
self.assertEqual(repr(ast.parse(test)), snapshot)

def test_repr_large_input_crash(self):
# gh-125010: Fix use-after-free in ast repr()
source = "0x0" + "e" * 10_000
with self.assertRaisesRegex(ValueError,
r"Exceeds the limit \(\d+ digits\)"):
repr(ast.Constant(value=eval(source)))


class CopyTests(unittest.TestCase):
"""Test copying and pickling AST nodes."""
Expand Down Expand Up @@ -1614,17 +1621,6 @@ def test_literal_eval_syntax_errors(self):
(\
\ ''')

def test_literal_eval_large_input_crash(self):
# gh-125010: Fix use-after-free in ast repr()
# Note: Without setting sys.set_int_max_str_digits(0),
# this code throws a 'ValueError: Exceeds the limit (4300 digits)'.
# With sys.set_int_max_str_digits(0),
# this code throws a 'ValueError: malformed node or string on line 1':
source = "{0x0" + "e" * 250_000 + "%" + "e" * 250_000 + "1j}"
with self.assertRaisesRegex(ValueError,
r"Exceeds the limit \(4300 digits\)"):
ast.literal_eval(source)

def test_bad_integer(self):
# issue13436: Bad error message with invalid numeric values
body = [ast.ImportFrom(module='time',
Expand Down