Skip to content

Commit 1a178bc

Browse files
committed
py/stream: Check for stream read function returning too many bytes.
This only happens if the underlying stream implementation is malformed, but results in unsigned integer overflow and out of bounds read otherwise. Second fix for #13046 - allows for possibility an invalid result comes back from a different stream implementation. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <angus@redyak.com.au>
1 parent a26ccdd commit 1a178bc

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

py/stream.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ mp_uint_t mp_stream_rw(mp_obj_t stream, void *buf_, mp_uint_t size, int *errcode
6464
if (out_sz == 0) {
6565
return done;
6666
}
67+
if (out_sz != MP_STREAM_ERROR && out_sz > size) {
68+
// This can only happen if the filesystem implementation returned invalid out_sz
69+
*errcode = MP_EINVAL;
70+
out_sz = MP_STREAM_ERROR;
71+
}
6772
if (out_sz == MP_STREAM_ERROR) {
6873
// If we read something before getting EAGAIN, don't leak it
6974
if (mp_is_nonblocking_error(*errcode) && done != 0) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy