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 failures and a crash when using an uninitialized struct.Struct object #75960

Open
orenmn mannequin opened this issue Oct 13, 2017 · 4 comments · Fixed by #94532
Open

assertion failures and a crash when using an uninitialized struct.Struct object #75960

orenmn mannequin opened this issue Oct 13, 2017 · 4 comments · Fixed by #94532
Assignees
Labels
3.10 only security fixes 3.11 only security fixes 3.12 bugs and security fixes extension-modules C modules in the Modules dir type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@orenmn
Copy link
Mannequin

orenmn mannequin commented Oct 13, 2017

BPO 31779
Nosy @mdickinson, @meadori, @berkerpeksag, @serhiy-storchaka, @orenmn, @izbyshev, @iritkatriel
PRs
  • bpo-31779: Prevent assertion failures and a crash when using an uninitialized struct.Struct object #3984
  • 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 = None
    created_at = <Date 2017-10-13.10:54:20.321>
    labels = ['extension-modules', '3.10', '3.9', 'type-crash', '3.11']
    title = 'assertion failures and a crash when using an uninitialized struct.Struct object'
    updated_at = <Date 2021-10-19.10:22:17.196>
    user = 'https://github.com/orenmn'

    bugs.python.org fields:

    activity = <Date 2021-10-19.10:22:17.196>
    actor = 'iritkatriel'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Extension Modules']
    creation = <Date 2017-10-13.10:54:20.321>
    creator = 'Oren Milman'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 31779
    keywords = ['patch']
    message_count = 3.0
    messages = ['304328', '325462', '404285']
    nosy_count = 7.0
    nosy_names = ['mark.dickinson', 'meador.inge', 'berker.peksag', 'serhiy.storchaka', 'Oren Milman', 'izbyshev', 'iritkatriel']
    pr_nums = ['3984']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue31779'
    versions = ['Python 3.9', 'Python 3.10', 'Python 3.11']

    @orenmn
    Copy link
    Mannequin Author

    orenmn mannequin commented Oct 13, 2017

    The following code causes an assertion failure:
    import _struct
    struct_obj = _struct.Struct.__new__(_struct.Struct)
    struct_obj.iter_unpack(b'foo')

    This is because Struct_iter_unpack() (in Modules/_struct.c) assumes that
    Struct.init() was called, and so it does assert(self->s_codes != NULL);.

    The same happens in (almost) every method of Struct, and in s_get_format(), so
    in all them, too, we would get an assertion failure in case of an uninitialized
    Struct object.
    The exception is sizeof(), which doesn't have an assert, and simply
    crashes while trying to iterate over self->s_codes.

    I would open a PR to fix this soon.

    @orenmn orenmn mannequin added 3.7 (EOL) end of life extension-modules C modules in the Modules dir type-crash A hard crash of the interpreter, possibly with a core dump labels Oct 13, 2017
    @izbyshev
    Copy link
    Mannequin

    izbyshev mannequin commented Sep 15, 2018

    What are the drawbacks of moving all code from __init__ to __new__, at least in master branch (3.8)? IMO it's much more robust than playing whack-a-mole both with ref/memleaks caused by repeated calls to __init__ and absence of initialization checks in all methods.

    @izbyshev izbyshev mannequin added the 3.8 only security fixes label Sep 15, 2018
    @iritkatriel
    Copy link
    Member

    Reproduced on 3.11.

    @iritkatriel iritkatriel added 3.9 only security fixes 3.10 only security fixes 3.11 only security fixes and removed 3.7 (EOL) end of life 3.8 only security fixes labels Oct 19, 2021
    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    @kumaraditya303 kumaraditya303 added 3.12 bugs and security fixes and removed 3.9 only security fixes labels Jul 3, 2022
    @kumaraditya303 kumaraditya303 self-assigned this Jul 3, 2022
    @mdickinson
    Copy link
    Member

    Re-opening: the original fix for this issue has been reverted, since it broke code for users in the wild who were subclassing struct.Struct.

    @mdickinson mdickinson reopened this Nov 26, 2023
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    3.10 only security fixes 3.11 only security fixes 3.12 bugs and security fixes extension-modules C modules in the Modules dir type-crash A hard crash of the interpreter, possibly with a core dump
    Projects
    None yet
    Development

    Successfully merging a pull request may close this issue.

    3 participants