about summary refs log tree commit diff
path: root/library/std/src/io/tests.rs
diff options
context:
space:
mode:
authorConrad Ludgate <conradludgate@gmail.com>2024-02-03 11:30:26 +0000
committerConrad Ludgate <conradludgate@gmail.com>2024-02-03 11:30:26 +0000
commita27e45a71bd9743cebfbac74ccd3d0f50cc1a190 (patch)
tree5adfe2e92b06aca6600bd19aeb4ed37676acdd8f /library/std/src/io/tests.rs
parentbf3c6c5bed498f41ad815641319a1ad9bcecb8e8 (diff)
downloadrust-a27e45a71bd9743cebfbac74ccd3d0f50cc1a190.tar.gz
rust-a27e45a71bd9743cebfbac74ccd3d0f50cc1a190.zip
fix #120603 by adding a check in default_read_buf
Diffstat (limited to 'library/std/src/io/tests.rs')
-rw-r--r--library/std/src/io/tests.rs16
1 files changed, 16 insertions, 0 deletions
diff --git a/library/std/src/io/tests.rs b/library/std/src/io/tests.rs
index bda5b721adc..c0179f7f227 100644
--- a/library/std/src/io/tests.rs
+++ b/library/std/src/io/tests.rs
@@ -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();
+}