diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2013-11-18 00:24:31 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2013-11-18 00:24:31 (GMT) |
commit | 83ed42bfbf003bd7720e2893a4da18a300f48fa8 (patch) | |
tree | 2cd8bbcc537317d94caa06581abf06ce9b0a700f | |
parent | 74387f5cac59d9cdafdd98e91f796d4731bd533a (diff) | |
download | cpython-83ed42bfbf003bd7720e2893a4da18a300f48fa8.zip cpython-83ed42bfbf003bd7720e2893a4da18a300f48fa8.tar.gz cpython-83ed42bfbf003bd7720e2893a4da18a300f48fa8.tar.bz2 |
sqlite: raise an OverflowError if the result is longer than INT_MAX bytes
Fix a compiler warning on Windows 64-bit
-rw-r--r-- | Modules/_sqlite/connection.c | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/Modules/_sqlite/connection.c b/Modules/_sqlite/connection.c index 7365a88..50c6f0a 100644 --- a/Modules/_sqlite/connection.c +++ b/Modules/_sqlite/connection.c @@ -522,10 +522,16 @@ _pysqlite_set_result(sqlite3_context* context, PyObject* py_val) const char* buffer; Py_ssize_t buflen; if (PyObject_AsCharBuffer(py_val, &buffer, &buflen) != 0) { - PyErr_SetString(PyExc_ValueError, "could not convert BLOB to buffer"); + PyErr_SetString(PyExc_ValueError, + "could not convert BLOB to buffer"); return -1; } - sqlite3_result_blob(context, buffer, buflen, SQLITE_TRANSIENT); + if (buflen > INT_MAX) { + PyErr_SetString(PyExc_OverflowError, + "BLOB longer than INT_MAX bytes"); + return -1; + } + sqlite3_result_blob(context, buffer, (int)buflen, SQLITE_TRANSIENT); } else { return -1; } |