]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-131505: Move len boundary assertions before using len. (#131536)
authornaya451 <41294408+naya451@users.noreply.github.com>
Mon, 19 May 2025 15:10:23 +0000 (18:10 +0300)
committerGitHub <noreply@github.com>
Mon, 19 May 2025 15:10:23 +0000 (08:10 -0700)
Move len boundary assertions before using len.

Modules/_io/bytesio.c

index 4cde5f87032a3fec062485b78263e61226ce488d..61cfec435fe60fb3339a1874c943ce4d837fd615 100644 (file)
@@ -607,9 +607,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);