Skip to content

Commit

Permalink
gh-100370: fix OverflowError in sqlite3.Connection.blobopen for 32-bi…
Browse files Browse the repository at this point in the history
…t builds
  • Loading branch information
erlend-aasland committed Apr 26, 2023
1 parent 222c63f commit 9559cdd
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
9 changes: 4 additions & 5 deletions Modules/_sqlite/clinic/connection.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 22 additions & 4 deletions Modules/_sqlite/connection.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,20 @@ autocommit_converter(PyObject *val, enum autocommit_mode *result)
return 0;
}

static int
sqlite3_int64_converter(PyObject *obj, sqlite3_int64 *result)
{
if (!PyLong_Check(obj)) {
PyErr_SetString(PyExc_TypeError, "expected 'int'");
return 0;
}
*result = _pysqlite_long_as_int64(obj);
if (PyErr_Occurred()) {
return 0;
}
return 1;
}

#define clinic_state() (pysqlite_get_state_by_type(Py_TYPE(self)))
#include "clinic/connection.c.h"
#undef clinic_state
Expand Down Expand Up @@ -186,8 +200,12 @@ class Autocommit_converter(CConverter):
type = "enum autocommit_mode"
converter = "autocommit_converter"
class sqlite3_int64_converter(CConverter):
type = "sqlite3_int64"
converter = "sqlite3_int64_converter"
[python start generated code]*/
/*[python end generated code: output=da39a3ee5e6b4b0d input=bc2aa6c7ba0c5f8f]*/
/*[python end generated code: output=da39a3ee5e6b4b0d input=dff8760fb1eba6a1]*/

// NB: This needs to be in sync with the sqlite3.connect docstring
/*[clinic input]
Expand Down Expand Up @@ -481,7 +499,7 @@ _sqlite3.Connection.blobopen as blobopen
Table name.
column as col: str
Column name.
row: int
row: sqlite3_int64
Row index.
/
*
Expand All @@ -495,8 +513,8 @@ Open and return a BLOB object.

static PyObject *
blobopen_impl(pysqlite_Connection *self, const char *table, const char *col,
int row, int readonly, const char *name)
/*[clinic end generated code: output=0c8e2e58516d0b5c input=fa73c83aa7a7ddee]*/
sqlite3_int64 row, int readonly, const char *name)
/*[clinic end generated code: output=6a02d43efb885d1c input=23576bd1108d8774]*/
{
if (!pysqlite_check_thread(self) || !pysqlite_check_connection(self)) {
return NULL;
Expand Down

0 comments on commit 9559cdd

Please sign in to comment.