[issue34695] sqlite3: Cache.get() crashes if Cache.__init__() was not called

2018-09-15 Thread Berker Peksag


Berker Peksag  added the comment:

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.

--
stage:  -> patch review
status: open -> closed

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34695] sqlite3: Cache.get() crashes if Cache.__init__() was not called

2018-09-15 Thread Berker Peksag


Change by Berker Peksag :


--
stage: patch review -> resolved

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34695] sqlite3: Cache.get() crashes if Cache.__init__() was not called

2018-09-15 Thread Serhiy Storchaka


Serhiy Storchaka  added the comment:

This is a duplicate of issue31734.

--
resolution:  -> duplicate
stage: patch review -> 
superseder:  -> crash or SystemError in sqlite3.Cache in case it is 
uninitialized or partially initialized

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34695] sqlite3: Cache.get() crashes if Cache.__init__() was not called

2018-09-15 Thread Alexey Izbyshev


Change by Alexey Izbyshev :


--
keywords: +patch
pull_requests: +8754
stage:  -> patch review

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue34695] sqlite3: Cache.get() crashes if Cache.__init__() was not called

2018-09-15 Thread Alexey Izbyshev


New submission from Alexey Izbyshev :

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.

--
components: Extension Modules
messages: 325440
nosy: berker.peksag, ghaering, izbyshev, serhiy.storchaka
priority: normal
severity: normal
status: open
title: sqlite3: Cache.get() crashes if Cache.__init__() was not called
type: crash
versions: Python 2.7, Python 3.6, Python 3.7, Python 3.8

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com