Skip to content
Prev Previous commit
Next Next commit
Assert lenght and offset
  • Loading branch information
Erlend E. Aasland committed Apr 16, 2022
commit 37a5c38c6ce5a922493e4cea7a8e5a9267263855
4 changes: 4 additions & 0 deletions Modules/_sqlite/blob.c
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ blob_seterror(pysqlite_Blob *self, int rc)
static PyObject *
inner_read(pysqlite_Blob *self, Py_ssize_t length, Py_ssize_t offset)
{
assert(length <= sqlite3_blob_bytes(self->blob));
assert(offset <= sqlite3_blob_bytes(self->blob) - self->offset);

PyObject *buffer = PyBytes_FromStringAndSize(NULL, length);
if (buffer == NULL) {
return NULL;
Expand Down Expand Up @@ -191,6 +194,7 @@ inner_write(pysqlite_Blob *self, const void *buf, Py_ssize_t len,
return -1;
}

assert(offset <= remaining_len);
int rc;
Py_BEGIN_ALLOW_THREADS
rc = sqlite3_blob_write(self->blob, buf, (int)len, (int)offset);
Expand Down