Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
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
6 changes: 6 additions & 0 deletions Lib/test/test_ast/test_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -1614,6 +1614,12 @@ def test_literal_eval_syntax_errors(self):
(\
\ ''')

def test_literal_eval_large_input_crash(self):
# gh-125010: Fix use-after-free in ast repr()
source = "{0x0" + "e" * 250_000 + "%" + "e" * 250_000 + "1j}"
with self.assertRaisesRegex(ValueError, "Exceeds the limit"):
ast.literal_eval(source)

def test_bad_integer(self):
# issue13436: Bad error message with invalid numeric values
body = [ast.ImportFrom(module='time',
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix a use-after-free bug in the :func:`repr` implementation of
:class:`ast.AST` nodes.
4 changes: 2 additions & 2 deletions Parser/asdl_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -1604,14 +1604,14 @@ def visitModule(self, mod):
value_repr = PyObject_Repr(value);
}

Py_DECREF(value);

if (!value_repr) {
Py_DECREF(name);
Py_DECREF(value);
goto error;
}

Py_DECREF(value);

if (i > 0) {
if (_PyUnicodeWriter_WriteASCIIString(&writer, ", ", 2) < 0) {
Py_DECREF(name);
Expand Down
4 changes: 2 additions & 2 deletions Python/Python-ast.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading