From: Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> Date: Tue, 20 May 2025 09:57:39 +0000 (+0200) Subject: [3.14] gh-131505: Move len boundary assertions before using len. (GH-131536) (GH... X-Git-Tag: v3.14.0b2~104 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=ccaf865364692087dc74252dd411f6356a1d43f0;p=thirdparty%2FPython%2Fcpython.git [3.14] gh-131505: Move len boundary assertions before using len. (GH-131536) (GH-134239) gh-131505: Move len boundary assertions before using len. (GH-131536) Move len boundary assertions before using len. (cherry picked from commit c45e661226558e997e265cf53ce1419213cc10b7) Co-authored-by: naya451 <41294408+naya451@users.noreply.github.com> --- diff --git a/Modules/_io/bytesio.c b/Modules/_io/bytesio.c index e45a2d1a16dc..8bc7aeacf294 100644 --- a/Modules/_io/bytesio.c +++ b/Modules/_io/bytesio.c @@ -583,9 +583,9 @@ _io_BytesIO_readinto_impl(bytesio *self, Py_buffer *buffer) len = 0; } - memcpy(buffer->buf, PyBytes_AS_STRING(self->buf) + self->pos, len); 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; return PyLong_FromSsize_t(len);