Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
9 changes: 9 additions & 0 deletions Lib/test/test_ast/test_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -3309,6 +3309,15 @@ class MoreFieldsThanTypes(ast.AST):
self.assertEqual(obj.a, 1)
self.assertEqual(obj.b, 2)

def test_malformed_fields_with_bytes(self):
class BadFields(ast.AST):
_fields = (b'\xff'*64,)
_field_types = {'a': int}

# This should not crash
with self.assertWarnsRegex(DeprecationWarning, r"Field b'\\xff\\xff.*' .*"):
obj = BadFields()

def test_complete_field_types(self):
class _AllFieldTypes(ast.AST):
_fields = ('a', 'b')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix potential buffer overflow in :class:`ast.AST` node initialization when
encountering malformed :attr:`~ast.AST._fields` containing non-:class:`str`.
4 changes: 2 additions & 2 deletions Parser/asdl_c.py
Original file line number Diff line number Diff line change
Expand Up @@ -1009,7 +1009,7 @@ def visitModule(self, mod):
else {
if (PyErr_WarnFormat(
PyExc_DeprecationWarning, 1,
"Field '%U' is missing from %.400s._field_types. "
"Field %R is missing from %.400s._field_types. "
"This will become an error in Python 3.15.",
name, Py_TYPE(self)->tp_name
) < 0) {
Expand Down Expand Up @@ -1044,7 +1044,7 @@ def visitModule(self, mod):
// simple field (e.g., identifier)
if (PyErr_WarnFormat(
PyExc_DeprecationWarning, 1,
"%.400s.__init__ missing 1 required positional argument: '%U'. "
"%.400s.__init__ missing 1 required positional argument: %R. "
"This will become an error in Python 3.15.",
Py_TYPE(self)->tp_name, name
) < 0) {
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