Repository navigation
sqlite3: Blob crashes when using a negative-step slice #150449
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or errorextension-modulesC modules in the Modules dirC modules in the Modules dir
on May 26, 2026 Not all sequences support extended slices (with step), especially with step < 0. Does it currently work with positive
step? Supporting step < 0 is a new feature, this change can only go in main.But crash and SystemError are unacceptable. In older versions we need to raise a TypeError or a ValueError for step < 0.
Not all sequences support extended slices (with step), especially with step < 0. Does it currently work with positive
step? Supporting step < 0 is a new feature, this change can only go in main.Yes, positive steps already work.
Test results on Python 3.13.4:
blob[0:10:2] = [0, 2, 4, 6, 8] blob[0:15:3] = [0, 3, 6, 9, 12] blob[1:10:2] = [1, 3, 5, 7, 9] after write blob[0:10:2] = [65, 66, 67, 68, 69] blob[9:0:-2] raises SystemError: Negative size passed to PyBytes_FromStringAndSizeThe Python data model notes that step support is optional:
Some sequences also support “extended slicing” with a third “step” parameter
Data Model §3.2.5 SequencesSince positive steps already work, I was wondering: once a type accepts a
stepargument at all, should it handle both positive and negative steps? Or isstep < 0still considered a separate addition?Either way, I'll prepare backport PRs that raise
ValueErrorforstep < 0in 3.13, 3.14 and 3.15.- added 5 commits that reference this issue
on May 30, 2026 9 remaining items
- added 4 commits that reference this issue
on Aug 11, 2026 - added3.13only security fixesonly security fixes3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixes3.16new features, bugs and security fixesnew features, bugs and security fixestype-featureA feature request or enhancementA feature request or enhancement
on Aug 14, 2026 So, 3.16 got a correct support for negative indices, 3.13-3.15 will get a bugfix.
Reacted by Jiseok CHOI- added a commit that references this issue
on Oct 9, 2026
Metadata
Metadata
Assignees
Labels
Projects
- StatusShow more project fieldsNo status
What happened?
sqlite3.Blobcrashes when you use a negative step in a slice — both for reading and writing.The sequence operations docs say
s[i:j:k]with negativekis valid, andbytearrayhandles it fine.Reading also crashes:
blob[9:0:-2]raises the same error.On Python 3.11.6 and 3.14.5 the error is
SystemError: Negative size passed to PyBytes_FromStringAndSize.On the current main branch
read_multiplewas changed to usePyBytesWriter_Create, so the message is nowValueError: size must be >= 0— but the root cause is the same.CPython versions tested on:
3.11.6, 3.14.5, main(629da5c)
Operating systems tested on:
macOS - 26.3.1 (a)(25D771280a)
Related
PyObject *read_multiple(pysqlite_Blob *, Py_ssize_t, Py_ssize_t): Assertion 'offset < sqlite3_blob_bytes(self->blob)' failed#142787 / gh-142787: Fix assertion failure in sqlite3 blob slice #142824 — different bug (assertion failure on empty slice, already fixed)s[i:j:k], negative k)I'd like to work on a fix for this. I'll submit a PR.
Linked PRs