Skip to content
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

assertion failure in PyErr_WriteUnraisable() in case of an exception with a bad __module__ #75599

Closed
orenmn mannequin opened this issue Sep 11, 2017 · 7 comments
Closed
Labels
3.7 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@orenmn
Copy link
Mannequin

orenmn mannequin commented Sep 11, 2017

BPO 31418
Nosy @serhiy-storchaka, @orenmn
PRs
  • bpo-31418: Fix an assertion failure in case of an exception with a bad __module__ attribute #3539
  • [3.6] bpo-31418: Fix an assertion failure in PyErr_WriteUnraisable() in case of an exception with a bad __module__ attribute. (GH-3539) #3556
  • 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 = None
    closed_at = <Date 2017-09-14.06:42:14.343>
    created_at = <Date 2017-09-11.12:49:19.794>
    labels = ['interpreter-core', '3.7', 'type-crash']
    title = 'assertion failure in PyErr_WriteUnraisable() in case of an exception with a bad __module__'
    updated_at = <Date 2017-09-14.06:42:14.342>
    user = 'https://github.com/orenmn'

    bugs.python.org fields:

    activity = <Date 2017-09-14.06:42:14.342>
    actor = 'serhiy.storchaka'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-09-14.06:42:14.343>
    closer = 'serhiy.storchaka'
    components = ['Interpreter Core']
    creation = <Date 2017-09-11.12:49:19.794>
    creator = 'Oren Milman'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 31418
    keywords = ['patch']
    message_count = 7.0
    messages = ['301872', '301873', '301874', '302042', '302047', '302126', '302145']
    nosy_count = 2.0
    nosy_names = ['serhiy.storchaka', 'Oren Milman']
    pr_nums = ['3539', '3556']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue31418'
    versions = ['Python 3.6', 'Python 3.7']

    @orenmn
    Copy link
    Mannequin Author

    orenmn mannequin commented Sep 11, 2017

    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 '<unknown>' as the module name
    in the traceback?

    @orenmn orenmn mannequin added 3.7 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump labels Sep 11, 2017
    @serhiy-storchaka
    Copy link
    Member

    Printing '<unknown>' LGTM.

    Implicit converting to str can raise a warning or exception if __module__ is a bytes object.

    @serhiy-storchaka
    Copy link
    Member

    I think this patch doesn't need a test (which would require using a subprocess).

    @orenmn
    Copy link
    Mannequin Author

    orenmn mannequin commented Sep 13, 2017

    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?

    @serhiy-storchaka
    Copy link
    Member

    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.

    @serhiy-storchaka
    Copy link
    Member

    New changeset f6e61df 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. (bpo-3539)
    f6e61df

    @serhiy-storchaka
    Copy link
    Member

    New changeset 5dbb28e 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) (bpo-3556)
    5dbb28e

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.7 (EOL) end of life interpreter-core (Objects, Python, Grammar, and Parser dirs) type-crash A hard crash of the interpreter, possibly with a core dump
    Projects
    None yet
    Development

    No branches or pull requests

    1 participant