Skip to content

crashes when calling methods of an uninitialized zipimport.zipimporter object #75962

Closed

Description

@orenmn
mannequin
BPO 31781
Nosy @brettcannon, @orenmn
PRs
  • bpo-31781: Prevent crashes when calling methods of an uninitialized zipimport.zipimporter object #3986
  • 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-10-20.20:43:37.214>
    created_at = <Date 2017-10-13.16:56:47.582>
    labels = ['extension-modules', '3.7', 'type-crash']
    title = 'crashes when calling methods of an uninitialized zipimport.zipimporter object'
    updated_at = <Date 2017-10-20.20:43:37.213>
    user = 'https://github.com/orenmn'

    bugs.python.org fields:

    activity = <Date 2017-10-20.20:43:37.213>
    actor = 'brett.cannon'
    assignee = 'none'
    closed = True
    closed_date = <Date 2017-10-20.20:43:37.214>
    closer = 'brett.cannon'
    components = ['Extension Modules']
    creation = <Date 2017-10-13.16:56:47.582>
    creator = 'Oren Milman'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 31781
    keywords = ['patch']
    message_count = 3.0
    messages = ['304346', '304680', '304681']
    nosy_count = 2.0
    nosy_names = ['brett.cannon', 'Oren Milman']
    pr_nums = ['3986']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue31781'
    versions = ['Python 3.7']

    Activity

    1. orenmn commented on Oct 13, 2017

      orenmnmannequin
      MannequinAuthor

      The following code crashes:
      import zipimport
      zi = zipimport.zipimporter.__new__(zipimport.zipimporter)
      zi.find_module('foo')

      This is because get_module_info() (in Modules/zipimport.c) assumes that the
      zipimporter object is initialized, so it assumes that self->prefix is not
      NULL, and passes it to make_filename(), which crashes.

      get_module_code() makes the same assumption, and zipimport_zipimporter_get_data_impl()
      assumes that self->archive is not NULL, and passes it to PyUnicode_GET_LENGTH(),
      which crashes.
      Thus, every method of an uninitialized zipimporter object might crash.

      I would open a PR to fix this soon.

    2. added
      type-crashA hard crash of the interpreter, possibly with a core dump
      on Oct 13, 2017
    3. brettcannon commented on Oct 20, 2017

      @brettcannon
      Member

      New changeset db60a5b by Brett Cannon (Oren Milman) in branch 'master':
      bpo-31781: Prevent crashes when calling methods of an uninitialized zipimport.zipimporter object (GH-3986)
      db60a5b

    4. brettcannon commented on Oct 20, 2017

      @brettcannon
      Member

      As always, thanks for the fix, Oren!

    5. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      3.7 (EOL)end of lifeextension-modulesC modules in the Modules dirtype-crashA hard crash of the interpreter, possibly with a core dump

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions