Repository navigation
PyLong_AsInt32() and friends modify *value when they raise OverflowError #156101
Copy link
Copy link
Closed
Labels
3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixes3.16new features, bugs and security fixesnew features, bugs and security fixesextension-modulesC modules in the Modules dirC modules in the Modules dirstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-C-APItopic-sqlite3type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Activity
- addedtype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or errorstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directoryextension-modulesC modules in the Modules dirC modules in the Modules dir3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixes3.16new features, bugs and security fixesnew features, bugs and security fixes
on Aug 20, 2026 cc @vstinner
Either the functions should leave *value unchanged on error, or the documentation should say that its value is unspecified after a failure.
IMO they should leave
*valueunchanged on error. They can use a temporary variable: I wrote PR gh-156727 to do that.- added a commit that references this issue
on Aug 31, 2026 - added a commit that references this issue
on Oct 9, 2026
Metadata
Metadata
Assignees
Labels
3.14bugs and security fixesbugs and security fixes3.15bugs and security fixesbugs and security fixes3.16new features, bugs and security fixesnew features, bugs and security fixesextension-modulesC modules in the Modules dirC modules in the Modules dirstdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-C-APItopic-sqlite3type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Projects
- StatusShow more project fieldsDone
Bug report
PyLong_AsInt32(),PyLong_AsUInt32(),PyLong_AsInt64()andPyLong_AsUInt64()are documented asbut on overflow they write the truncated value into *value before returning
-1.They are implemented on top of
PyLong_AsNativeBytes(), which copies the lowest bytes and reports the required size, and theLONG_TO_INT/LONG_TO_UINTmacros inObjects/longobject.conly raiseOverflowErrorafterwards:This makes the straightforward usage unsafe.
For example,
_sqlite3_Cursor_arraysize_set_impl()inModules/_sqlite/cursor.cpasses the target field directly:Either the functions should leave *value unchanged on error, or the documentation should say that its value is unspecified after a failure.
Linked PRs