classification
Title: assertion failures in case a module has a bad __name__ attribute
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, ethan.furman, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2017-09-16 18:00 by Oren Milman, last changed 2017-09-27 06:46 by serhiy.storchaka. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 3620 merged Oren Milman, 2017-09-16 21:18
PR 3773 merged serhiy.storchaka, 2017-09-26 23:21
Messages (3)
msg302348 - (view) Author: Oren Milman (Oren Milman) * Date: 2017-09-16 18:00
The following code causes an assertion failure:
import os
os.__name__ = None
os.does_not_exist

this is because module_getattro() (in Objects/moduleobject.c) assumes that
__name__ is a string, and passes it to PyErr_Format(), which asserts it is a
string.


if we fixed that one (so that the code above would raise an AttributeError),
the following code would still cause an assertion failure:

import os
os.__name__ = None
from os import does_not_exist


this is because import_from() (in Python/ceval.c) also assumes that __name__
is a string, and passes it to PyUnicode_FromFormat(), which asserts it is a
string.


BTW, while we are in module_getattro(): isn't the second call to PyErr_Clear()
redundant? (Ethan, IIUC, you worked on this as part of #8297 some years ago..)
msg302514 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-09-19 11:23
New changeset 6db7033192cd537ca987a65971acb01206c3ba82 by Serhiy Storchaka (Oren Milman) in branch 'master':
bpo-31492: Fix assertion failures in case of a module with a bad __name__ attribute. (#3620)
https://github.com/python/cpython/commit/6db7033192cd537ca987a65971acb01206c3ba82
msg303090 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2017-09-27 04:33
New changeset f0db2dfda777ad3380e7816cabe4c4240f31687f by Serhiy Storchaka in branch '3.6':
[3.6] bpo-31492: Fix assertion failures in case of a module with a bad __name__ attribute. (GH-3620). (#3773)
https://github.com/python/cpython/commit/f0db2dfda777ad3380e7816cabe4c4240f31687f
History
Date User Action Args
2017-09-27 06:46:43serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2017-09-27 04:33:03serhiy.storchakasetmessages: + msg303090
2017-09-26 23:21:45serhiy.storchakasetstage: backport needed -> patch review
pull_requests: + pull_request3760
2017-09-19 13:31:09serhiy.storchakasetstage: patch review -> backport needed
versions: + Python 3.6
2017-09-19 11:23:04serhiy.storchakasetmessages: + msg302514
2017-09-16 21:18:42Oren Milmansetkeywords: + patch
stage: patch review
pull_requests: + pull_request3611
2017-09-16 18:41:17serhiy.storchakasetnosy: + serhiy.storchaka
2017-09-16 18:20:01Oren Milmansetcomponents: + Interpreter Core, - Extension Modules
2017-09-16 18:00:45Oren Milmancreate