Rollup merge of #119991 - kornelski:endless-read, r=the8472

Reject infinitely-sized reads from io::Repeat

These calls would always run out of memory.

Related to #117925
This commit is contained in:
Guillaume Gomez 2024-01-30 11:19:12 +01:00 committed by GitHub
commit 5db58538cf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -204,6 +204,16 @@ impl Read for Repeat {
Ok(())
}
/// This function is not supported by `io::Repeat`, because there's no end of its data
fn read_to_end(&mut self, _: &mut Vec<u8>) -> io::Result<usize> {
Err(io::Error::from(io::ErrorKind::OutOfMemory))
}
/// This function is not supported by `io::Repeat`, because there's no end of its data
fn read_to_string(&mut self, _: &mut String) -> io::Result<usize> {
Err(io::Error::from(io::ErrorKind::OutOfMemory))
}
#[inline]
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
let mut nwritten = 0;