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.

Author izbyshev
Recipients berker.peksag, ghaering, izbyshev, serhiy.storchaka
Date 2018-09-15.15:52:33
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1537026753.58.0.956365154283.issue34695@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2018-09-15 15:52:33izbyshevsetrecipients: + izbyshev, ghaering, berker.peksag, serhiy.storchaka
2018-09-15 15:52:33izbyshevsetmessageid: <1537026753.58.0.956365154283.issue34695@psf.upfronthosting.co.za>
2018-09-15 15:52:33izbyshevlinkissue34695 messages
2018-09-15 15:52:33izbyshevcreate