This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: sqlite crashes with converters mutating cursor
Type: crash Stage: patch review
Components: Extension Modules Versions: Python 3.8, Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: berker.peksag, erlendaasland, ghaering, sir-sigurd
Priority: normal Keywords: patch

Created on 2019-02-22 07:44 by sir-sigurd, last changed 2022-04-11 14:59 by admin.

Pull Requests
URL Status Linked Edit
PR 11984 closed sir-sigurd, 2019-02-22 07:48
PR 29054 open erlendaasland, 2021-10-19 09:48
Messages (3)
msg336283 - (view) Author: Sergey Fedoseev (sir-sigurd) * Date: 2019-02-22 07:44
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.
msg400335 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2021-08-26 11:00
After GH-27884 (bpo-44976) there is no longer a segfault.

I suggest to expand the test suite with the reproducer Sergey provided.
msg400336 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2021-08-26 11:04
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)
History
Date User Action Args
2022-04-11 14:59:11adminsetgithub: 80254
2021-10-19 09:48:51erlendaaslandsetpull_requests: + pull_request27326
2021-08-26 11:04:41erlendaaslandsetmessages: + msg400336
2021-08-26 11:00:16erlendaaslandsetmessages: + msg400335
2021-08-26 10:59:30erlendaaslandsetstatus: pending -> open

messages: - msg400334
2021-08-26 10:58:04erlendaaslandsetstatus: open -> pending

messages: + msg400334
2020-05-25 12:16:32erlendaaslandsetnosy: + erlendaasland
2019-06-22 04:32:19xtreaksetnosy: + berker.peksag
2019-02-22 07:53:44SilentGhostsetnosy: + ghaering

versions: + Python 3.7, Python 3.8
2019-02-22 07:48:13sir-sigurdsetkeywords: + patch
stage: patch review
pull_requests: + pull_request12008
2019-02-22 07:44:47sir-sigurdcreate