Issue 31418: assertion failure in PyErr_WriteUnraisable() in case of an exception with a bad module (original) (raw)

This issue has been migrated to GitHub: https://github.com/python/cpython/issues/75599

classification

Title: assertion failure in PyErr_WriteUnraisable() in case of an exception with a bad __module__
Type: crash Stage: resolved
Components: Interpreter Core Versions: Python 3.7, Python 3.6

process

Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Oren Milman, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2017-09-11 12:49 by Oren Milman, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 3539 merged Oren Milman,2017-09-13 10:26
PR 3556 merged python-dev,2017-09-13 22:30
Messages (7)
msg301872 - (view) Author: Oren Milman (Oren Milman) * Date: 2017-09-11 12:49
The following code causes an assertion failure in PyErr_WriteUnraisable() (in Python/errors.c): class BadException(Exception): __module__ = None class BadClass: def __del__(self): raise BadException foo = BadClass() del foo this is because PyErr_WriteUnraisable() assumes that __module__ is a string, and passes it to _PyUnicode_EqualToASCIIId(), which asserts it received a string. what is the wanted behavior in such a case? should we ignore the bad __module__ and print '' as the module name in the traceback?
msg301873 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-09-11 13:25
Printing '' LGTM. Implicit converting to str can raise a warning or exception if __module__ is a bytes object.
msg301874 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-09-11 13:27
I think this patch doesn't need a test (which would require using a subprocess).
msg302042 - (view) Author: Oren Milman (Oren Milman) * Date: 2017-09-13 09:48
what do you mean by 'Implicit converting to str can raise a warning or exception if __module__ is a bytes object.'? should we treat __module__ differently in case it is a bytes object?
msg302047 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-09-13 10:02
PyFile_WriteObject(moduleName, f, Py_PRINT_RAW) implicitly converts its argument to string. I mean that treating non-string moduleName the same way as string moduleName not equal to string "builtins" and calling PyFile_WriteObject() would cause other problem. Treating non-string moduleName the same way as moduleName==NULL LGTM.
msg302126 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-09-13 22:30
New changeset f6e61df01536493f1280cd07639c7ff9bffb2cdc by Serhiy Storchaka (Oren Milman) in branch 'master': bpo-31418: Fix an assertion failure in PyErr_WriteUnraisable() in case of an exception with a bad __module__ attribute. (#3539) https://github.com/python/cpython/commit/f6e61df01536493f1280cd07639c7ff9bffb2cdc
msg302145 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-09-14 06:41
New changeset 5dbb28ececdd0382d85b164aaf37bec1ae08036c by Serhiy Storchaka (Miss Islington (bot)) in branch '3.6': [3.6] bpo-31418: Fix an assertion failure in PyErr_WriteUnraisable() in case of an exception with a bad __module__ attribute. (GH-3539) (#3556) https://github.com/python/cpython/commit/5dbb28ececdd0382d85b164aaf37bec1ae08036c
History
Date User Action Args
2022-04-11 14:58:52 admin set github: 75599
2017-09-14 06:42:14 serhiy.storchaka set status: open -> closedresolution: fixedstage: patch review -> resolved
2017-09-14 06:41:41 serhiy.storchaka set messages: +
2017-09-13 22:30:16 python-dev set pull_requests: + <pull%5Frequest3548>
2017-09-13 22:30:08 serhiy.storchaka set messages: +
2017-09-13 22:27:35 serhiy.storchaka set versions: + Python 3.6
2017-09-13 10:26:02 Oren Milman set keywords: + patchstage: patch reviewpull_requests: + <pull%5Frequest3534>
2017-09-13 10:02:15 serhiy.storchaka set messages: +
2017-09-13 09:48:48 Oren Milman set messages: +
2017-09-11 13:27:17 serhiy.storchaka set messages: +
2017-09-11 13:25:24 serhiy.storchaka set nosy: + serhiy.storchakamessages: +
2017-09-11 12:49:19 Oren Milman create