From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Fri, 27 Feb 2026 00:12:51 +0000 (+0100) Subject: [3.14] gh-142787: Handle empty sqlite3 blob slices (GH-142824) (#145297) X-Git-Tag: v3.14.4~233 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=bc6a7a2b0cdc254712171125afd8b4f4817dc0c4;p=thirdparty%2FPython%2Fcpython.git [3.14] gh-142787: Handle empty sqlite3 blob slices (GH-142824) (#145297) (cherry picked from commit 06b0920f1292690a22ab2b271dfefe2c63cacf07) Co-authored-by: A.Ibrahim --- diff --git a/Lib/test/test_sqlite3/test_dbapi.py b/Lib/test/test_sqlite3/test_dbapi.py index 1e595bdbd645..7e55785bd4a6 100644 --- a/Lib/test/test_sqlite3/test_dbapi.py +++ b/Lib/test/test_sqlite3/test_dbapi.py @@ -1387,6 +1387,11 @@ class BlobTests(unittest.TestCase): def test_blob_get_empty_slice(self): self.assertEqual(self.blob[5:5], b"") + def test_blob_get_empty_slice_oob_indices(self): + self.cx.execute("insert into test(b) values (?)", (b"abc",)) + with self.cx.blobopen("test", "b", 2) as blob: + self.assertEqual(blob[5:-5], b"") + def test_blob_get_slice_negative_index(self): self.assertEqual(self.blob[5:-5], self.data[5:-5]) diff --git a/Misc/NEWS.d/next/Library/2025-12-16-13-34-48.gh-issue-142787.wNitJX.rst b/Misc/NEWS.d/next/Library/2025-12-16-13-34-48.gh-issue-142787.wNitJX.rst new file mode 100644 index 000000000000..e928bd2cac72 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2025-12-16-13-34-48.gh-issue-142787.wNitJX.rst @@ -0,0 +1,2 @@ +Fix assertion failure in :mod:`sqlite3` blob subscript when slicing with +indices that result in an empty slice. diff --git a/Modules/_sqlite/blob.c b/Modules/_sqlite/blob.c index aafefbf316e0..161431069538 100644 --- a/Modules/_sqlite/blob.c +++ b/Modules/_sqlite/blob.c @@ -434,6 +434,10 @@ subscript_slice(pysqlite_Blob *self, PyObject *item) return NULL; } + if (len == 0) { + return PyBytes_FromStringAndSize(NULL, 0); + } + if (step == 1) { return read_multiple(self, len, start); }