diff options
author | Erlend Egeberg Aasland <erlend.aasland@innova.no> | 2021-02-18 15:44:43 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-18 15:44:43 (GMT) |
commit | 47feb1feb28631b6647699b7633109aa85340966 (patch) | |
tree | b0554c136370d7456a2561084f90997bf7dfcf55 /Modules | |
parent | 7be00ee64a2ced73c00ec855c7265e2ba795213d (diff) | |
download | cpython-47feb1feb28631b6647699b7633109aa85340966.zip cpython-47feb1feb28631b6647699b7633109aa85340966.tar.gz cpython-47feb1feb28631b6647699b7633109aa85340966.tar.bz2 |
bpo-43249: sqlite3_column_bytes() must follow sqlite_column_blob() (GH-24562)
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_sqlite/cursor.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/Modules/_sqlite/cursor.c b/Modules/_sqlite/cursor.c index f8fe11e..63176b8 100644 --- a/Modules/_sqlite/cursor.c +++ b/Modules/_sqlite/cursor.c @@ -278,9 +278,15 @@ _pysqlite_fetch_one_row(pysqlite_Cursor* self) converter = Py_None; } + /* + * Note, sqlite3_column_bytes() must come after sqlite3_column_blob() + * or sqlite3_column_text(). + * + * See https://sqlite.org/c3ref/column_blob.html for details. + */ if (converter != Py_None) { - nbytes = sqlite3_column_bytes(self->statement->st, i); val_str = (const char*)sqlite3_column_blob(self->statement->st, i); + nbytes = sqlite3_column_bytes(self->statement->st, i); if (!val_str) { converted = Py_NewRef(Py_None); } else { @@ -330,9 +336,13 @@ _pysqlite_fetch_one_row(pysqlite_Cursor* self) } } else { /* coltype == SQLITE_BLOB */ - nbytes = sqlite3_column_bytes(self->statement->st, i); - converted = PyBytes_FromStringAndSize( - sqlite3_column_blob(self->statement->st, i), nbytes); + const char *blob = sqlite3_column_blob(self->statement->st, i); + if (!blob) { + converted = Py_NewRef(Py_None); + } else { + nbytes = sqlite3_column_bytes(self->statement->st, i); + converted = PyBytes_FromStringAndSize(blob, nbytes); + } } } |