mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
bpo-43369: sqlite3_column_{text,blob} failures now raise MemoryError (GH-24723)
This commit is contained in:
parent
c61ec7e6b8
commit
e161ec5dd7
3 changed files with 49 additions and 12 deletions
|
@ -262,6 +262,7 @@ _pysqlite_fetch_one_row(pysqlite_Cursor* self)
|
|||
if (!row)
|
||||
return NULL;
|
||||
|
||||
sqlite3 *db = self->connection->db;
|
||||
for (i = 0; i < numcols; i++) {
|
||||
if (self->connection->detect_types
|
||||
&& self->row_cast_map != NULL
|
||||
|
@ -280,17 +281,19 @@ _pysqlite_fetch_one_row(pysqlite_Cursor* self)
|
|||
* See https://sqlite.org/c3ref/column_blob.html for details.
|
||||
*/
|
||||
if (converter != Py_None) {
|
||||
const char *blob = (const char*)sqlite3_column_blob(self->statement->st, i);
|
||||
nbytes = sqlite3_column_bytes(self->statement->st, i);
|
||||
if (!blob) {
|
||||
converted = Py_NewRef(Py_None);
|
||||
} else {
|
||||
item = PyBytes_FromStringAndSize(blob, nbytes);
|
||||
if (!item)
|
||||
goto error;
|
||||
converted = PyObject_CallOneArg(converter, item);
|
||||
Py_DECREF(item);
|
||||
const void *blob = sqlite3_column_blob(self->statement->st, i);
|
||||
if (blob == NULL && sqlite3_errcode(db) == SQLITE_NOMEM) {
|
||||
PyErr_NoMemory();
|
||||
goto error;
|
||||
}
|
||||
|
||||
nbytes = sqlite3_column_bytes(self->statement->st, i);
|
||||
item = PyBytes_FromStringAndSize(blob, nbytes);
|
||||
if (item == NULL) {
|
||||
goto error;
|
||||
}
|
||||
converted = PyObject_CallOneArg(converter, item);
|
||||
Py_DECREF(item);
|
||||
} else {
|
||||
Py_BEGIN_ALLOW_THREADS
|
||||
coltype = sqlite3_column_type(self->statement->st, i);
|
||||
|
@ -303,6 +306,11 @@ _pysqlite_fetch_one_row(pysqlite_Cursor* self)
|
|||
converted = PyFloat_FromDouble(sqlite3_column_double(self->statement->st, i));
|
||||
} else if (coltype == SQLITE_TEXT) {
|
||||
const char *text = (const char*)sqlite3_column_text(self->statement->st, i);
|
||||
if (text == NULL && sqlite3_errcode(db) == SQLITE_NOMEM) {
|
||||
PyErr_NoMemory();
|
||||
goto error;
|
||||
}
|
||||
|
||||
nbytes = sqlite3_column_bytes(self->statement->st, i);
|
||||
if (self->connection->text_factory == (PyObject*)&PyUnicode_Type) {
|
||||
converted = PyUnicode_FromStringAndSize(text, nbytes);
|
||||
|
@ -332,7 +340,12 @@ _pysqlite_fetch_one_row(pysqlite_Cursor* self)
|
|||
}
|
||||
} else {
|
||||
/* coltype == SQLITE_BLOB */
|
||||
const char *blob = sqlite3_column_blob(self->statement->st, i);
|
||||
const void *blob = sqlite3_column_blob(self->statement->st, i);
|
||||
if (blob == NULL && sqlite3_errcode(db) == SQLITE_NOMEM) {
|
||||
PyErr_NoMemory();
|
||||
goto error;
|
||||
}
|
||||
|
||||
nbytes = sqlite3_column_bytes(self->statement->st, i);
|
||||
converted = PyBytes_FromStringAndSize(blob, nbytes);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue