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

crash or SystemError in sqlite3.Cache in case it is uninitialized or partially initialized #75915

Closed
orenmn mannequin opened this issue Oct 9, 2017 · 3 comments
Closed
Labels
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

Comments

@orenmn
Copy link
Mannequin

orenmn mannequin commented Oct 9, 2017

BPO 31734
Nosy @ericvw, @berkerpeksag, @serhiy-storchaka, @orenmn
PRs
  • bpo-31734: Raise a ValueError instead of crashing, when the get() method of an uninitialized sqlite3.Cache object is called #3939
  • 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 2018-09-08.18:33:48.526>
    created_at = <Date 2017-10-09.13:54:05.065>
    labels = ['extension-modules', '3.7', 'type-crash']
    title = 'crash or SystemError in sqlite3.Cache in case it is uninitialized or partially initialized'
    updated_at = <Date 2018-09-08.18:33:48.526>
    user = 'https://github.com/orenmn'

    bugs.python.org fields:

    activity = <Date 2018-09-08.18:33:48.526>
    actor = 'berker.peksag'
    assignee = 'none'
    closed = True
    closed_date = <Date 2018-09-08.18:33:48.526>
    closer = 'berker.peksag'
    components = ['Extension Modules']
    creation = <Date 2017-10-09.13:54:05.065>
    creator = 'Oren Milman'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 31734
    keywords = ['patch']
    message_count = 3.0
    messages = ['303958', '303963', '322171']
    nosy_count = 5.0
    nosy_names = ['ghaering', 'ericvw', 'berker.peksag', 'serhiy.storchaka', 'Oren Milman']
    pr_nums = ['3939']
    priority = 'normal'
    resolution = 'wont fix'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue31734'
    versions = ['Python 2.7', 'Python 3.6', 'Python 3.7']

    @orenmn
    Copy link
    Mannequin Author

    orenmn mannequin commented Oct 9, 2017

    The following code causes a crash:
    import sqlite3
    cache = sqlite3.Cache.__new__(sqlite3.Cache)
    cache.get(None)

    This is because pysqlite_cache_get() (in Modules/_sqlite/cache.c) assumes that
    the Cache object is initialized, and so it passes self->mapping to
    PyDict_GetItem(), which assumes it is not NULL, and crashes.

    Also, the following code causes a SystemError ('null argument to internal
    routine'), as well as refleaks in the deallocation of the Cache object:
    import sqlite3
    cache = sqlite3.Cache(str)
    try:
    cache.__init__()
    except TypeError:
    pass
    cache.get(None)

    This is because pysqlite_cache_init() first sets self->factory to NULL, and
    only then parses its arguments, so in case it fails to parse the arguments
    (e.g. due to a wrong number of arguments) we are left with a partially
    initialized Cache object.

    While we are here, we should also fix refleaks that occur when
    sqlite3.Cache.__init__() is called more than once.

    @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 9, 2017
    @orenmn
    Copy link
    Mannequin Author

    orenmn mannequin commented Oct 9, 2017

    Also, the following code results in a memory leak:
    import sqlite3
    cache = sqlite3.Cache.__new__(sqlite3.Cache)

    This is because pysqlite_cache_dealloc() just returns in case of an uninitialized
    Cache object.

    @berkerpeksag
    Copy link
    Member

    Thanks for the PR and for the work you've been doing to fix similar bugs in Python!

    The Cache class is an implementation detail and it has no practical use for third party users. See bpo-30262 for a discussion on making it private.

    If a user somehow finds the Cache class, wants to do something with it, it's their problem if it crashes the interpreter.

    So, unless you can demonstrate that these problems can be reproduced without using the Cache class directly, I'm inclined to close this issue as 'wontfix'.

    @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 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

    No branches or pull requests

    1 participant