Skip to content

Commit d3bb3a7

Browse files
Issue #24257: Fixed segmentation fault in sqlite3.Row constructor with faked
cursor type.
1 parent 2607e65 commit d3bb3a7

3 files changed

Lines changed: 12 additions & 1 deletion

File tree

Lib/sqlite3/test/factory.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,14 @@ def CheckSqliteRowAsSequence(self):
170170
self.assertEqual(list(reversed(row)), list(reversed(as_tuple)))
171171
self.assertIsInstance(row, Sequence)
172172

173+
def CheckFakeCursorClass(self):
174+
# Issue #24257: Incorrect use of PyObject_IsInstance() caused
175+
# segmentation fault.
176+
class FakeCursor(str):
177+
__class__ = sqlite.Cursor
178+
cur = self.con.cursor(factory=FakeCursor)
179+
self.assertRaises(TypeError, sqlite.Row, cur, ())
180+
173181
def tearDown(self):
174182
self.con.close()
175183

Misc/NEWS

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ Core and Builtins
1818
Library
1919
-------
2020

21+
- Issue #24257: Fixed segmentation fault in sqlite3.Row constructor with faked
22+
cursor type.
23+
2124
- Issue #22107: tempfile.gettempdir() and tempfile.mkdtemp() now try again
2225
when a directory with the chosen name already exists on Windows as well as
2326
on Unix. tempfile.mkstemp() now fails early if parent directory is not

Modules/_sqlite/row.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pysqlite_row_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
4747
if (!PyArg_ParseTuple(args, "OO", &cursor, &data))
4848
return NULL;
4949

50-
if (!PyObject_IsInstance((PyObject*)cursor, (PyObject*)&pysqlite_CursorType)) {
50+
if (!PyObject_TypeCheck((PyObject*)cursor, &pysqlite_CursorType)) {
5151
PyErr_SetString(PyExc_TypeError, "instance of cursor required for first argument");
5252
return NULL;
5353
}

0 commit comments

Comments
 (0)