You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
obj2ast's error handling can lead to python crashing with a C-level assertion failure #54600
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee=Noneclosed_at=<Date2010-11-20.01:39:03.489>created_at=<Date2010-11-11.20:53:42.187>labels= ['interpreter-core', 'type-crash']
title="obj2ast's error handling can lead to python crashing with a C-level assertion failure"updated_at=<Date2010-11-20.01:39:03.487>user='https://github.com/davidmalcolm'
In various places within the generated Python/Python-ast.c, error handling generates a repr() and raises exceptions accordingly.
Currently in py3k the generated code uses PyBytes_AS_STRING() on the repr. My understanding is that repr() should be a PyUnicodeObject, not a PyBytesObject. This seems to be unchanged from r63682, which was a mass-change of PyString to PyBytes from 2 years ago.
This leads to a python crashing with an assertion failure:
test_compile_ast (main.TestSpecifics) ... python: Python/Python-ast.c:5835: obj2ast_expr: Assertion `((((((PyObject*)(tmp))->ob_type))->tp_flags & ((1L<<27))) != 0)' failed.
when invoking compile() on certain (malformed) trees of ast objects.
FWIW, it's not clear to what extent _PyUnicode_AS_STRING is deprecated, Include/unicodeobject.h currently has:
*** This API is for interpreter INTERNAL USE ONLY and will likely
*** be removed or changed for Python 3.1.
but I hope it won't be, it's far too useful.
IMOabetterpatchwouldbetousethe %Rformatspecification:
PyErr_Format(
PyExc_TypeError, "expected some sort of mod, but got %R", obj);
AndnoneedtousePyObject_Reprandthetemporaryvariable!
Activity
davidmalcolm commentedon Nov 11, 2010
In various places within the generated Python/Python-ast.c, error handling generates a repr() and raises exceptions accordingly.
Currently in py3k the generated code uses PyBytes_AS_STRING() on the repr. My understanding is that repr() should be a PyUnicodeObject, not a PyBytesObject. This seems to be unchanged from r63682, which was a mass-change of PyString to PyBytes from 2 years ago.
This leads to a python crashing with an assertion failure:
test_compile_ast (main.TestSpecifics) ... python: Python/Python-ast.c:5835: obj2ast_expr: Assertion `((((((PyObject*)(tmp))->ob_type))->tp_flags & ((1L<<27))) != 0)' failed.
when invoking compile() on certain (malformed) trees of ast objects.
davidmalcolm commentedon Nov 11, 2010
The attached patch:
FWIW, it's not clear to what extent _PyUnicode_AS_STRING is deprecated, Include/unicodeobject.h currently has:
*** This API is for interpreter INTERNAL USE ONLY and will likely
*** be removed or changed for Python 3.1.
but I hope it won't be, it's far too useful.
amauryfa commentedon Nov 11, 2010
benjaminp commentedon Nov 20, 2010
r86538