https://github.com/python/cpython/commit/c45e661226558e997e265cf53ce1419213cc10b7
commit: c45e661226558e997e265cf53ce1419213cc10b7
branch: main
author: naya451 <41294408+naya...@users.noreply.github.com>
committer: gpshead <g...@krypto.org>
date: 2025-05-19T08:10:23-07:00
summary:

gh-131505: Move len boundary assertions before using len. (#131536)

Move len boundary assertions before using len.

files:
M Modules/_io/bytesio.c

diff --git a/Modules/_io/bytesio.c b/Modules/_io/bytesio.c
index 4cde5f87032a3f..61cfec435fe60f 100644
--- a/Modules/_io/bytesio.c
+++ b/Modules/_io/bytesio.c
@@ -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);

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: arch...@mail-archive.com

Reply via email to