Repository navigation
Commit 1502a52
gh-160781: Fix BytesIO overflow handling for large sizes
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>1 parent 4521718 commit 1502a52
4 files changed
Lines changed: 18 additions & 1 deletion
File tree
- Lib/test/test_io
- Misc/NEWS.d/next/Library
- Modules/_io
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
591 | 591 | | |
592 | 592 | | |
593 | 593 | | |
| 594 | + | |
| 595 | + | |
| 596 | + | |
| 597 | + | |
594 | 598 | | |
595 | 599 | | |
596 | 600 | | |
| |||
984 | 988 | | |
985 | 989 | | |
986 | 990 | | |
| 991 | + | |
| 992 | + | |
| 993 | + | |
| 994 | + | |
| 995 | + | |
987 | 996 | | |
988 | 997 | | |
989 | 998 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
221 | 221 | | |
222 | 222 | | |
223 | 223 | | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
224 | 227 | | |
225 | 228 | | |
226 | 229 | | |
| |||
755 | 758 | | |
756 | 759 | | |
757 | 760 | | |
758 | | - | |
| 761 | + | |
759 | 762 | | |
760 | 763 | | |
761 | 764 | | |
| |||
0 commit comments