Skip to content

Commit 9559cdd

Browse files
gh-100370: fix OverflowError in sqlite3.Connection.blobopen for 32-bit builds
1 parent 222c63f commit 9559cdd

File tree

2 files changed

+26
-9
lines changed

2 files changed

+26
-9
lines changed

Modules/_sqlite/clinic/connection.c.h

Lines changed: 4 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Modules/_sqlite/connection.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,20 @@ autocommit_converter(PyObject *val, enum autocommit_mode *result)
116116
return 0;
117117
}
118118

119+
static int
120+
sqlite3_int64_converter(PyObject *obj, sqlite3_int64 *result)
121+
{
122+
if (!PyLong_Check(obj)) {
123+
PyErr_SetString(PyExc_TypeError, "expected 'int'");
124+
return 0;
125+
}
126+
*result = _pysqlite_long_as_int64(obj);
127+
if (PyErr_Occurred()) {
128+
return 0;
129+
}
130+
return 1;
131+
}
132+
119133
#define clinic_state() (pysqlite_get_state_by_type(Py_TYPE(self)))
120134
#include "clinic/connection.c.h"
121135
#undef clinic_state
@@ -186,8 +200,12 @@ class Autocommit_converter(CConverter):
186200
type = "enum autocommit_mode"
187201
converter = "autocommit_converter"
188202
203+
class sqlite3_int64_converter(CConverter):
204+
type = "sqlite3_int64"
205+
converter = "sqlite3_int64_converter"
206+
189207
[python start generated code]*/
190-
/*[python end generated code: output=da39a3ee5e6b4b0d input=bc2aa6c7ba0c5f8f]*/
208+
/*[python end generated code: output=da39a3ee5e6b4b0d input=dff8760fb1eba6a1]*/
191209

192210
// NB: This needs to be in sync with the sqlite3.connect docstring
193211
/*[clinic input]
@@ -481,7 +499,7 @@ _sqlite3.Connection.blobopen as blobopen
481499
Table name.
482500
column as col: str
483501
Column name.
484-
row: int
502+
row: sqlite3_int64
485503
Row index.
486504
/
487505
*
@@ -495,8 +513,8 @@ Open and return a BLOB object.
495513

496514
static PyObject *
497515
blobopen_impl(pysqlite_Connection *self, const char *table, const char *col,
498-
int row, int readonly, const char *name)
499-
/*[clinic end generated code: output=0c8e2e58516d0b5c input=fa73c83aa7a7ddee]*/
516+
sqlite3_int64 row, int readonly, const char *name)
517+
/*[clinic end generated code: output=6a02d43efb885d1c input=23576bd1108d8774]*/
500518
{
501519
if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
502520
return NULL;

0 commit comments

Comments
 (0)