Skip to content

assertion failure at Modules/_sqlite/blob.c:146: PyObject *read_multiple(pysqlite_Blob *, Py_ssize_t, Py_ssize_t): Assertion 'offset < sqlite3_blob_bytes(self->blob)' failed #142787

Description

@YuanchengJiang

Crash report

What happened?

import sqlite3

# 1. Setup an in-memory database with a BLOB column
con = sqlite3.connect(':memory:')
con.execute('create table test(b blob)')

# 2. Insert a small amount of data.
# The unicode character '\u2603' (Snowman) is 3 bytes in UTF-8 (b'\xe2\x98\x83').
# The blob size will be 3.
con.execute('insert into test(b) values (?)', ('\u2603',))

# 3. Open the BLOB for incremental I/O
# Table: 'test', Column: 'b', Row: 1
blob = con.blobopen('test', 'b', 1)

# 4. Trigger the crash
# We request a slice starting at index 5 (which is beyond the blob size of 3)
# and ending at index -5 (which wraps around to before the start).
# This combination causes the internal 'offset' calculation in C to assert
# failing that the offset (5) is not less than the blob bytes (3).
blob[5:-5]
python: ../Modules/_sqlite/blob.c:146: PyObject *read_multiple(pysqlite_Blob *, Py_ssize_t, Py_ssize_t): Assertion `offset < sqlite3_blob_bytes(self->blob)' failed.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Output from running 'python -VV' on the command line:

No response

Linked PRs

Activity

  1. added
    type-crashA hard crash of the interpreter, possibly with a core dump
    on Dec 16, 2025
  2. added a commit that references this issue on Dec 16, 2025
  3. moved this to In Progress in sqlite3 issueson Dec 16, 2025
  4. added a commit that references this issue on Feb 26, 2026
  5. moved this from In Progress to Done in sqlite3 issueson Feb 26, 2026
  6. added 2 commits that reference this issue on Feb 26, 2026
  7. added 2 commits that reference this issue on Feb 27, 2026
  8. erlend-aasland commented on Feb 27, 2026

    @erlend-aasland
    Contributor

    Thanks for the report, @YuanchengJiang, and thanks for the fix @abdoulrasheed!

  9. added a commit that references this issue on Feb 28, 2026
  10. added a commit that references this issue on Apr 25, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    extension-modulesC modules in the Modules dirtopic-sqlite3type-crashA hard crash of the interpreter, possibly with a core dump

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions