Skip to content

gh-150449: Fix sqlite3.Blob crash with negative-step slices#150450

Open
ever0de wants to merge 1 commit into
python:mainfrom
ever0de:gh-150449-fix-sqlite-blob-negative-step-slice
Open

gh-150449: Fix sqlite3.Blob crash with negative-step slices#150450
ever0de wants to merge 1 commit into
python:mainfrom
ever0de:gh-150449-fix-sqlite-blob-negative-step-slice

Conversation

@ever0de
Copy link
Copy Markdown
Contributor

@ever0de ever0de commented May 26, 2026

Reading or writing a sqlite3.Blob with a negative-step slice such as blob[9:0:-2] caused a crash (SystemError on older versions, ValueError on current main) because the C code computed stop - start as the read length, which is negative for negative steps.

Fix subscript_slice() and ass_subscript_slice() in Modules/_sqlite/blob.c to handle both positive and negative steps correctly:

  • For step > 1: keep reading [start, stop) and indexing forward as before.
  • For step < -1: read the contiguous range [start+(len-1)*step, start] and index backward with stride -step.

Reading or writing a sqlite3.Blob with a negative-step slice such as
blob[9:0:-2] caused a crash (SystemError on older versions, ValueError
on current main) because the C code computed stop - start as the read
length, which is negative for negative steps.

Fix subscript_slice() and ass_subscript_slice() in Modules/_sqlite/blob.c
to handle both positive and negative steps correctly:
- For step > 1: keep reading [start, stop) and indexing forward as before.
- For step < -1: read the contiguous range [start+(len-1)*step, start]
  and index backward with stride -step.
@ever0de ever0de force-pushed the gh-150449-fix-sqlite-blob-negative-step-slice branch from 561ce7f to 24ade8a Compare May 26, 2026 06:58
@ever0de ever0de marked this pull request as ready for review May 26, 2026 06:58
@ever0de ever0de requested a review from erlend-aasland as a code owner May 26, 2026 06:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant