Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

sqlite3.Connection.blobopen() can fail with OverflowError on large rowids #100370

Closed
Assignees
erlend-aasland
Labels
3.11only security fixes3.12only security fixestopic-sqlite3type-bugAn unexpected behavior, bug, or error
@TheCatPlusPlus

Description

@TheCatPlusPlus

Bug report

blobopen internally usesint to hold the requested rowid ([1],[2]), but SQLite rowids are actually 64-bit integers:

int sqlite3_blob_open(  sqlite3*,  const char *zDb,  const char *zTable,  const char *zColumn,  sqlite3_int64 iRow, // <-- the rowid parameter  int flags,  sqlite3_blob **ppBlob);

This makes an attempt to open a blob with large rowid raise anOverflowError when Python is compiled with 32-bitint, which is the case on Windows even when compiling as 64-bit application.

This might seem like an edge case, but anyINTEGER PRIMARY KEY in a rowid tablealiases rowid, which means any application that uses non-autoincrement primary keys (e.g. timestamps, checksums) is likely to hit this very trivially -- I know I did on basically the first insert. You don't need to have more than 2**32 rows or anything like that for this to happen.

100% reproducible with:

importsqlite3con=sqlite3.connect(':memory:')rowid=2**32con.execute("create table t(t blob)")con.execute("insert into t(rowid, t) values (?, zeroblob(1))", (rowid,))con.blobopen('t','t',rowid)

Expected: nothing (i.e. successful call)
Instead:

Traceback (most recent call last):  File "E:\Temp\blob.py", line 10, in <module>    con.blobopen('t', 't', rowid)OverflowError: Python int too large to convert to C int

Your environment

  • CPython versions tested on: 3.11.0 (main, Oct 24 2022, 18:26:48) [MSC v.1933 64 bit (AMD64)], 3.12.0a3+ (heads/main-dirty:cb60b6131b, Dec 20 2022, 14:37:41) [MSC v.1934 64 bit (AMD64)]
  • Operating system and architecture: Windows x64

Linked PRs

Metadata

Metadata

Labels

3.11only security fixes3.12only security fixestopic-sqlite3type-bugAn unexpected behavior, bug, or error

Projects

Status

Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions


    [8]ページ先頭

    ©2009-2025 Movatter.jp