https://github.com/python/cpython/commit/f3a05316881dce6e6c0b2f6350188dfe9f3fb69b commit: f3a05316881dce6e6c0b2f6350188dfe9f3fb69b branch: 3.14 author: Miss Islington (bot) <[email protected]> committer: serhiy-storchaka <[email protected]> date: 2026-08-21T07:42:25Z summary:
[3.14] gh-156101: Fix sqlite3 Cursor.arraysize on a failed assignment (GH-156105) (GH-156157) PyLong_AsUInt32() stores 0 in the target on error, so the attribute was clobbered when the assigned value was too large. (cherry picked from commit 53760b3f8d76ecc5a69204b880afcec6d8ed706f) Co-authored-by: Serhiy Storchaka <[email protected]> files: A Misc/NEWS.d/next/Library/2026-08-20-12-10-00.gh-issue-156101.Qb2xNv.rst M Lib/test/test_sqlite3/test_dbapi.py M Modules/_sqlite/cursor.c diff --git a/Lib/test/test_sqlite3/test_dbapi.py b/Lib/test/test_sqlite3/test_dbapi.py index 7165729cd524f0..0bb3fb80f04c5c 100644 --- a/Lib/test/test_sqlite3/test_dbapi.py +++ b/Lib/test/test_sqlite3/test_dbapi.py @@ -1083,9 +1083,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 diff --git a/Misc/NEWS.d/next/Library/2026-08-20-12-10-00.gh-issue-156101.Qb2xNv.rst b/Misc/NEWS.d/next/Library/2026-08-20-12-10-00.gh-issue-156101.Qb2xNv.rst new file mode 100644 index 00000000000000..817f4a7207d7fa --- /dev/null +++ b/Misc/NEWS.d/next/Library/2026-08-20-12-10-00.gh-issue-156101.Qb2xNv.rst @@ -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. diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c index cb0f9adcc45a96..a4b5769040282a 100644 --- a/Modules/_sqlite/cursor.c +++ b/Modules/_sqlite/cursor.c @@ -1321,7 +1321,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[] = { _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3//lists/python-checkins.python.org Member address: [email protected]
