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

sqlite crashes with converters mutating cursor #80254

Closed
sir-sigurd mannequin opened this issue Feb 22, 2019 · 4 comments · Fixed by #29054
Closed

sqlite crashes with converters mutating cursor #80254

sir-sigurd mannequin opened this issue Feb 22, 2019 · 4 comments · Fixed by #29054
Labels
extension-modules C modules in the Modules dir type-crash A hard crash of the interpreter, possibly with a core dump

Comments

@sir-sigurd
Copy link
Mannequin

sir-sigurd mannequin commented Feb 22, 2019

BPO 36073
Nosy @berkerpeksag, @sir-sigurd, @erlend-aasland
PRs
  • bpo-36073: Raise ProgrammingError on recursive usage of cursors in sqlite converters #11984
  • gh-80254: Disallow recursive usage of cursors in sqlite3 converters #29054
  • 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 2019-02-22.07:44:47.863>
    labels = ['extension-modules', '3.7', '3.8', 'type-crash']
    title = 'sqlite crashes with converters mutating cursor'
    updated_at = <Date 2021-10-19.09:48:51.905>
    user = 'https://github.com/sir-sigurd'

    bugs.python.org fields:

    activity = <Date 2021-10-19.09:48:51.905>
    actor = 'erlendaasland'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['Extension Modules']
    creation = <Date 2019-02-22.07:44:47.863>
    creator = 'sir-sigurd'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 36073
    keywords = ['patch']
    message_count = 3.0
    messages = ['336283', '400335', '400336']
    nosy_count = 4.0
    nosy_names = ['ghaering', 'berker.peksag', 'sir-sigurd', 'erlendaasland']
    pr_nums = ['11984', '29054']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'crash'
    url = 'https://bugs.python.org/issue36073'
    versions = ['Python 3.7', 'Python 3.8']

    @sir-sigurd
    Copy link
    Mannequin Author

    sir-sigurd mannequin commented Feb 22, 2019

    It's somewhat similar to bpo-10811, but for converter function:

    In [197]: import sqlite3 as sqlite
    ...: con = sqlite.connect(':memory:', detect_types=sqlite.PARSE_COLNAMES)
    ...: cur = con.cursor()
    ...: sqlite.converters['CURSOR_INIT'] = lambda x: cur.__init__(con)
    ...:
    ...: cur.execute('create table test(x foo)')
    ...: cur.execute('insert into test(x) values (?)', ('foo',))
    ...: cur.execute('select x as "x [CURSOR_INIT]", x from test')
    ...:
    [1] 25718 segmentation fault python manage.py shell

    Similar to bpo-10811, proposed patch raises ProgrammingError instead of crashing.

    @sir-sigurd sir-sigurd mannequin added extension-modules C modules in the Modules dir type-crash A hard crash of the interpreter, possibly with a core dump labels Feb 22, 2019
    @SilentGhost SilentGhost mannequin added 3.7 (EOL) end of life 3.8 only security fixes labels Feb 22, 2019
    @erlend-aasland
    Copy link
    Contributor

    After #72071 (bpo-44976) there is no longer a segfault.

    I suggest to expand the test suite with the reproducer Sergey provided.

    @erlend-aasland
    Copy link
    Contributor

    Er, a little bit too fast there. There is still a crash, but it is of course postponed bco. bpo-44976. New reproducer:

    import sqlite3 as sqlite
    con = sqlite.connect(':memory:', detect_types=sqlite.PARSE_COLNAMES)
    cur = con.cursor()
    sqlite.converters['CURSOR_INIT'] = lambda x: cur.__init__(con)

    cur.execute('create table test(x foo)')
    cur.execute('insert into test(x) values (?)', ('foo',))
    for row in cur.execute('select x as "x [CURSOR_INIT]", x from test'):
    print(row)

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    JelleZijlstra added a commit that referenced this issue May 3, 2022
    …#29054)
    
    Co-authored-by: Sergey Fedoseev <fedoseev.sergey@gmail.com>
    Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
    @erlend-aasland erlend-aasland removed 3.8 only security fixes 3.7 (EOL) end of life labels May 3, 2022
    erlend-aasland added a commit to erlend-aasland/cpython that referenced this issue May 3, 2022
    …3` converters (python#29054)
    
    (cherry picked from commit f629dcf)
    
    Co-authored-by: Sergey Fedoseev <fedoseev.sergey@gmail.com>
    Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
    erlend-aasland added a commit to erlend-aasland/cpython that referenced this issue May 3, 2022
    …` converters
    
    (cherry picked from commit c908dc5)
    
    Co-authored-by: Sergey Fedoseev <fedoseev.sergey@gmail.com>
    Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
    JelleZijlstra pushed a commit that referenced this issue May 5, 2022
    …verters (#92274)
    
    * [3.10] gh-80254: Disallow recursive usage of cursors in `sqlite3` converters (#29054)
    
    (cherry picked from commit f629dcf)
    
    Co-authored-by: Sergey Fedoseev <fedoseev.sergey@gmail.com>
    Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
    
    * Fix ref leak in pysqlite_cursor_iternext
    JelleZijlstra pushed a commit that referenced this issue May 5, 2022
    …erters (#92278)
    
    * [3.9] gh-80254: Disallow recursive usage of cursors in `sqlite3` converters
    
    (cherry picked from commit c908dc5)
    
    Co-authored-by: Sergey Fedoseev <fedoseev.sergey@gmail.com>
    Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
    
    * Fix ref leak in pysqlite_cursor_iternext
    
    * Explicitly free resources at test tearDown()
    ambv pushed a commit that referenced this issue May 16, 2022
    …ters (#92333)
    
    (cherry picked from commit c908dc5)
    
    Co-authored-by: Sergey Fedoseev <fedoseev.sergey@gmail.com>
    Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
    ned-deily pushed a commit that referenced this issue May 23, 2022
    …ters (GH-92334)
    
    (cherry picked from commit c908dc5)
    
    Co-authored-by: Sergey Fedoseev <fedoseev.sergey@gmail.com>
    Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
    hello-adam pushed a commit to hello-adam/cpython that referenced this issue Jun 2, 2022
    …` converters (python#92278)
    
    * [3.9] pythongh-80254: Disallow recursive usage of cursors in `sqlite3` converters
    
    (cherry picked from commit c908dc5)
    
    Co-authored-by: Sergey Fedoseev <fedoseev.sergey@gmail.com>
    Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
    
    * Fix ref leak in pysqlite_cursor_iternext
    
    * Explicitly free resources at test tearDown()
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    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.

    1 participant