https://github.com/python/cpython/commit/7291b843d8bbd2a730747433e63c9197f2795037 commit: 7291b843d8bbd2a730747433e63c9197f2795037 branch: 3.15 author: Miss Islington (bot) <[email protected]> committer: JelleZijlstra <[email protected]> date: 2026-10-22T23:59:01Z summary:
[3.15] gh-159739: Keep SQLite list parameters alive while binding (GH-160192) (#160361) When a SQL parameter sequence is an exact list, sqlite3 retrieved an element as a borrowed reference before taking ownership. On free-threaded builds another thread can replace it in between, so binding can use a freed object and crash. Fetch a strong reference atomically. Backport to 3.15 and 3.14. (cherry picked from commit 4df47d8e60020f8961cab2be1ea7267bf16fd128) Co-authored-by: Jelle Zijlstra <[email protected]> files: A Misc/NEWS.d/next/Library/2026-10-21-21-26-10.gh-issue-159739.JIqZRY.rst M Modules/_sqlite/cursor.c diff --git a/Misc/NEWS.d/next/Library/2026-10-21-21-26-10.gh-issue-159739.JIqZRY.rst b/Misc/NEWS.d/next/Library/2026-10-21-21-26-10.gh-issue-159739.JIqZRY.rst new file mode 100644 index 000000000000000..fa000802ef713bf --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-10-21-21-26-10.gh-issue-159739.JIqZRY.rst @@ -0,0 +1 @@ +Fix a possible crash when a list of :mod:`sqlite3` parameters is modified concurrently on a free-threaded build. diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c index dd4204ff267d0a2..f7afb2c9f4ffabb 100644 --- a/Modules/_sqlite/cursor.c +++ b/Modules/_sqlite/cursor.c @@ -701,8 +701,7 @@ bind_parameters(pysqlite_state *state, pysqlite_Statement *self, PyObject *item = PyTuple_GET_ITEM(parameters, i); current_param = Py_NewRef(item); } else if (PyList_CheckExact(parameters)) { - PyObject *item = PyList_GetItem(parameters, i); - current_param = Py_XNewRef(item); + current_param = PyList_GetItemRef(parameters, i); } else { current_param = PySequence_GetItem(parameters, i); } _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3//lists/python-checkins.python.org Member address: [email protected]
