Skip to content

Commit bc6a7a2

Browse files
[3.14] gh-142787: Handle empty sqlite3 blob slices (GH-142824) (#145297)
(cherry picked from commit 06b0920) Co-authored-by: A.Ibrahim <abdulrasheedibrahim47@gmail.com>
1 parent 0810124 commit bc6a7a2

File tree

3 files changed

+11
-0
lines changed

3 files changed

+11
-0
lines changed

Lib/test/test_sqlite3/test_dbapi.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,6 +1387,11 @@ def test_blob_get_slice(self):
13871387
def test_blob_get_empty_slice(self):
13881388
self.assertEqual(self.blob[5:5], b"")
13891389

1390+
def test_blob_get_empty_slice_oob_indices(self):
1391+
self.cx.execute("insert into test(b) values (?)", (b"abc",))
1392+
with self.cx.blobopen("test", "b", 2) as blob:
1393+
self.assertEqual(blob[5:-5], b"")
1394+
13901395
def test_blob_get_slice_negative_index(self):
13911396
self.assertEqual(self.blob[5:-5], self.data[5:-5])
13921397

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix assertion failure in :mod:`sqlite3` blob subscript when slicing with
2+
indices that result in an empty slice.

Modules/_sqlite/blob.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -434,6 +434,10 @@ subscript_slice(pysqlite_Blob *self, PyObject *item)
434434
return NULL;
435435
}
436436

437+
if (len == 0) {
438+
return PyBytes_FromStringAndSize(NULL, 0);
439+
}
440+
437441
if (step == 1) {
438442
return read_multiple(self, len, start);
439443
}

0 commit comments

Comments
 (0)