Skip to content

Commit 83ed42b

Browse files
committed
sqlite: raise an OverflowError if the result is longer than INT_MAX bytes
Fix a compiler warning on Windows 64-bit
1 parent 74387f5 commit 83ed42b

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

Modules/_sqlite/connection.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -522,10 +522,16 @@ _pysqlite_set_result(sqlite3_context* context, PyObject* py_val)
522522
const char* buffer;
523523
Py_ssize_t buflen;
524524
if (PyObject_AsCharBuffer(py_val, &buffer, &buflen) != 0) {
525-
PyErr_SetString(PyExc_ValueError, "could not convert BLOB to buffer");
525+
PyErr_SetString(PyExc_ValueError,
526+
"could not convert BLOB to buffer");
526527
return -1;
527528
}
528-
sqlite3_result_blob(context, buffer, buflen, SQLITE_TRANSIENT);
529+
if (buflen > INT_MAX) {
530+
PyErr_SetString(PyExc_OverflowError,
531+
"BLOB longer than INT_MAX bytes");
532+
return -1;
533+
}
534+
sqlite3_result_blob(context, buffer, (int)buflen, SQLITE_TRANSIENT);
529535
} else {
530536
return -1;
531537
}

0 commit comments

Comments
 (0)