FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-141311: Avoid assertion in BytesIO readinto by cmaloney · Pull Request #141333 · python/cpython · GitHub

Repository navigation

Prev Previous commit
Next Next commit
Update for review comments
  • Loading branch information
cmaloney committed Nov 11, 2025
commit e06d274092971c7e5bb2fa977dc4c2226bcf7521
10 changes: 3 additions & 7 deletions Modules/_io/bytesio.c
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -436,11 +436,7 @@ read_bytes_lock_held(bytesio *self, Py_ssize_t size)
return Py_NewRef(self->buf);
}

/* gh-141311: avoid overflow with self->buf + self->pos */
if (self->pos >= PY_SSIZE_T_MAX - size) {
self->pos = PY_SSIZE_T_MAX;
size = 0;
}
/* gh-141311: avoid past end of self->buf access */
Comment thread
cmaloney marked this conversation as resolved.
Outdated
if (size == 0) {
return PyBytes_FromStringAndSize(NULL, 0);
}
Expand Down Expand Up @@ -619,12 +615,12 @@ _io_BytesIO_readinto_impl(bytesio *self, Py_buffer *buffer)
if (len > n) {
len = n;
if (len < 0) {
/* gh-141311: avoid overflow with self->buf + self->pos */
/* gh-141311: avoid past end of self->buf access */
return PyLong_FromSsize_t(0);
}
}

assert(self->pos + len < PY_SSIZE_T_MAX);
assert(self->pos + len <= PY_SSIZE_T_MAX);
assert(len >= 0);
memcpy(buffer->buf, PyBytes_AS_STRING(self->buf) + self->pos, len);
self->pos += len;
Expand Down

Back | FazBrowse Home | New Git URL