Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions Lib/test/test_sqlite3/test_dbapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -1075,9 +1075,14 @@ def test_invalid_array_size(self):
UINT32_MAX = (1 << 32) - 1
setter = functools.partial(setattr, self.cu, 'arraysize')

self.cu.arraysize = 2
self.assertRaises(TypeError, setter, 1.0)
self.assertRaises(ValueError, setter, -3)
self.assertRaises(OverflowError, setter, UINT32_MAX + 1)
self.assertRaises(OverflowError, setter, 2**1000)
self.assertRaises(ValueError, setter, -2**1000)
# a failed assignment does not change the value
self.assertEqual(self.cu.arraysize, 2)

def test_fetchmany(self):
# no active SQL statement
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix :attr:`sqlite3.Cursor.arraysize` being set to 0 if the assigned value is
too large.
The attribute is now left unchanged if the assignment fails.
7 changes: 6 additions & 1 deletion Modules/_sqlite/cursor.c
Original file line number Diff line number Diff line change
Expand Up @@ -1378,7 +1378,12 @@ static int
_sqlite3_Cursor_arraysize_set_impl(pysqlite_Cursor *self, PyObject *value)
/*[clinic end generated code: output=af59a6b09f8cce6e input=ace48cb114e26060]*/
{
return PyLong_AsUInt32(value, &self->arraysize);
uint32_t arraysize;
if (PyLong_AsUInt32(value, &arraysize) < 0) {
return -1;
}
self->arraysize = arraysize;
return 0;
}

static PyMethodDef cursor_methods[] = {
Expand Down
Loading