[issue4367] Patch for segmentation fault in ast_for_atom

Amaury Forgeot d'Arc report at bugs.python.org
Thu Nov 20 19:39:34 CET 2008


Amaury Forgeot d'Arc <amauryfa at gmail.com> added the comment:

I think I got the point: to decode strings like "\N{CHARACTER NAME}"
PyUnicode_DecodeUnicodeEscape imports the unicodedata module.
If this fails, PyErr_SetString(PyExc_UnicodeError, "some message")
is called.

The exception will eventually be caught by ast_for_atom (in
Python/ast.c), but the exception there is not normalized: type is
PyExc_UnicodeError when the value is a string. Hence the invalid cast.
The exception cannot be normalized there: UnicodeError.__init__ needs 5
arguments.

I think the error was to call PyErr_SetString in the first place.
The attached patch replaces it with PyErr_SetObject and a full
UnicodeDecodeError object.

This deserves a unit test, but I wonder how to reliably make the import
fail.

----------
keywords: +needs review
nosy: +amaury.forgeotdarc
Added file: http://bugs.python.org/file12078/bad_unicodeerror.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue4367>
_______________________________________


More information about the Python-bugs-list mailing list