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: sqlite3: Cache.get() crashes if Cache.__init__() was not called
Type: crash Stage: resolved
Components: Extension Modules Versions: Python 3.8, Python 3.7, Python 3.6, Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: crash or SystemError in sqlite3.Cache in case it is uninitialized or partially initialized
View: 31734
Assigned To: Nosy List: berker.peksag, ghaering, izbyshev, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2018-09-15 15:52 by izbyshev, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 9331 closed izbyshev, 2018-09-15 16:03
Messages (3)
msg325440 - (view) Author: Alexey Izbyshev (izbyshev) * (Python triager) Date: 2018-09-15 15:52
sqlite3.Cache allows users to create uninitialized instances because it relies on __init__() instead of __new__() for initialization, which can be skipped. Cache.get() crashes if called on an uninitialized instance:

>>> from sqlite3 import Cache
>>> Cache.__new__(Cache, None).get(42)
Segmentation fault (core dumped)

I see the following ways to fix this:

1) Explicitly check that the instance is initialized in Cache methods (this is what sqlite3 does for Connection and Cursor).

2) Move initialization from __init__() to __new__(). The latter can't be skipped due to Python safety checks. The issue here is that pysqlite_cache_init() is declared in Modules/_sqlite/cache.h, and while it's not directly called anywhere in Python sources, removing or changing it might be considered a change in public API.

3) Remove Cache from sqlite3 module dictionary. It's not clear to me why it's there because it's only used internally by Connection, is not documented, and there is no API to supply user-created Cache instances to sqlite3. Also, there are no tests for Cache.

I'll submit a PR implementing the first (most backwards-compatible) fix, but will be happy if (2), (3) or any other more reliable fixes can be considered.
msg325442 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2018-09-15 16:09
This is a duplicate of issue31734.
msg325443 - (view) Author: Berker Peksag (berker.peksag) * (Python committer) Date: 2018-09-15 16:13
Thanks for the report and for the patch! This is a duplicate of issue 31734. The Cache class is an implementation detail and it has no use of outside of the sqlite3 implementation as you already said.

For option 3, there is an open issue: #30262. IMO, the best way to fix this issue is to make it private.
History
Date User Action Args
2022-04-11 14:59:05adminsetgithub: 78876
2018-09-15 16:13:53berker.peksagsetstage: patch review -> resolved
2018-09-15 16:13:40berker.peksagsetstatus: open -> closed

messages: + msg325443
stage: patch review
2018-09-15 16:09:55serhiy.storchakasetsuperseder: crash or SystemError in sqlite3.Cache in case it is uninitialized or partially initialized
resolution: duplicate
messages: + msg325442
stage: patch review -> (no value)
2018-09-15 16:03:24izbyshevsetkeywords: + patch
stage: patch review
pull_requests: + pull_request8754
2018-09-15 15:52:33izbyshevcreate