New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple type confusions in unicode error handlers #68290
Comments
# Breakpoint 1, PyUnicodeEncodeError_GetEnd (exc=<X at remote 0x405730e4>, end=0xbf9e8f7c) at Objects/exceptions.c:1643 # Type confusion. IsInstance check is ineffective because of custom |
Here is simpler reproducer: import codecs
class X(str):
__class__ = UnicodeEncodeError
codecs.ignore_errors(X()) The problem is that PyObject_IsInstance() is fooled by custom __class__, but then builtin error handlers handle error object as having UnicodeEncodeError layout, while it doesn't. Here is a patch that fixes the issue by using PyObject_IsSubclass() of exc->ob_type instead of PyObject_IsInstance(). |
The patch does indeed fix the segmentation fault. However the exception message looks confusing: TypeError: don't know how to handle UnicodeEncodeError in error callback |
Here is a patch that makes error message consistent with type checking. |
Looks much better. However shouldn't: exc->ob_type->tp_name be: Py_TYPE(exc)->tp_name (although there are still many spots in the source that still use ob_type->tp_name) |
Py_TYPE() is necessary when the argument is not of type PyObject* (e.g. PyUnicodeObject*). |
Also fixed handling errors of PyObject_IsSubclass() (bpo-24115) in the _codecs module. |
New changeset 547bc11e3357 by Serhiy Storchaka in branch '2.7': New changeset 68eaa9409818 by Serhiy Storchaka in branch '3.4': New changeset 510819e5855e by Serhiy Storchaka in branch 'default': |
Greg Ewing suggested to use PyObject_TypeCheck (http://permalink.gmane.org/gmane.comp.python.devel/153216). |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: