]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.14] gh-131505: Move len boundary assertions before using len. (GH-131536) (GH...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 20 May 2025 09:57:39 +0000 (11:57 +0200)
committerGitHub <noreply@github.com>
Tue, 20 May 2025 09:57:39 +0000 (09:57 +0000)
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>
Modules/_io/bytesio.c

index e45a2d1a16dcba3767d36b396f6b806139f38238..8bc7aeacf294ba251f559f063fc7cfc82ab37ce5 100644 (file)
@@ -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);