mirror of https://github.com/python/cpython
gh-125010: Fix `use-after-free` in AST `repr()` (#125015)
This commit is contained in:
parent
3fc673e97d
commit
a1be83dae3
|
@ -789,6 +789,13 @@ class AST_Tests(unittest.TestCase):
|
|||
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."""
|
||||
|
|
|
@ -1608,7 +1608,6 @@ ast_repr_max_depth(AST_object *self, int depth)
|
|||
|
||||
if (!value_repr) {
|
||||
Py_DECREF(name);
|
||||
Py_DECREF(value);
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
|
|
@ -5809,7 +5809,6 @@ ast_repr_max_depth(AST_object *self, int depth)
|
|||
|
||||
if (!value_repr) {
|
||||
Py_DECREF(name);
|
||||
Py_DECREF(value);
|
||||
goto error;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue