← 输入框|github.com|刷新
Skip to content

gh-160781: Fix BytesIO overflow handling for large sizes - #160783

Open
cmaloney wants to merge 3 commits into
python:mainfrom
cmaloney:bio_1
Open

cmaloney wants to merge 3 commits into
python:mainfrom
cmaloney:bio_1

Conversation

@cmaloney

@cmaloney cmaloney commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

BytesIO.write() at a position near sys.maxsize raised SystemError ("Negative size passed to PyBytes_FromStringAndSize") because the overallocated buffer size could exceed PY_SSIZE_T_MAX. Check the computed allocation, not only the requested size.

BytesIO.truncate() converted its argument with PyLong_AsLong(), which rejects sizes above 2**31 - 1 on Windows where C long is 32-bit. Use PyNumber_AsSsize_t() like the Py_ssize_t Argument Clinic converter it used before.

BytesIO.write() at a position near sys.maxsize raised SystemError
("Negative size passed to PyBytes_FromStringAndSize") because the
overallocated buffer size could exceed PY_SSIZE_T_MAX.  Check the
computed allocation, not only the requested size.

BytesIO.truncate() converted its argument with PyLong_AsLong(), which
rejects sizes above 2**31 - 1 on Windows where C long is 32-bit.  Use
PyNumber_AsSsize_t() like the Py_ssize_t Argument Clinic converter it
used before.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cmaloney cmaloney added 3.14 bugs and security fixes 3.15 bugs and security fixes needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes and removed 3.14 bugs and security fixes 3.15 bugs and security fixes labels Oct 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting review needs backport to 3.14 bugs and security fixes needs backport to 3.15 bugs and security fixes

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant