fix #120603 by adding a check in default_read_buf

This commit is contained in:
Conrad Ludgate
2024-02-03 11:30:26 +00:00
parent bf3c6c5bed
commit a27e45a71b
2 changed files with 22 additions and 1 deletions

View File

@@ -652,3 +652,19 @@ fn bench_take_read_buf(b: &mut test::Bencher) {
[255; 128].take(64).read_buf(buf.unfilled()).unwrap();
});
}
// Issue #120603
#[test]
#[should_panic = "read should not return more bytes than there is capacity for in the read buffer"]
fn read_buf_broken_read() {
struct MalformedRead;
impl Read for MalformedRead {
fn read(&mut self, buf: &mut [u8]) -> io::Result<usize> {
// broken length calculation
Ok(buf.len() + 1)
}
}
BufReader::new(MalformedRead).read(&mut [0; 4]).unwrap();
}