test: Add tests for Cursor BufRead past end behavior
What changed, and why it matters
This commit only adds two new unit tests to the project's custom I/O library. The tests check that a Cursor (a simple in-memory reader) behaves the same way as Rust's standard library when asked to read past the end of its data: it should return an empty buffer and allow the position to advance without error. There is no code change that fixes or changes behavior, and nothing here indicates a security issue.
No action required. This is a test-only commit with no security relevance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff adds tests in io/src/lib.rs verifying that Cursor::fill_buf() returns an empty slice and that Cursor::consume() advances position beyond the buffer length when the cursor position is already past the end of the underlying data. This is purely a test addition; no implementation code is modified. The behavior being tested is consistent with std::io::Cursor semantics.
Changed components
io/src/lib.rs testsInspect captured patch +20 / −0
diff --git a/io/src/lib.rs b/io/src/lib.rs
index 6e287150..dcd463b5 100644
--- a/io/src/lib.rs
+++ b/io/src/lib.rs
@@ -517,4 +517,24 @@ mod tests {
assert_eq!(read, 32);
assert_eq!(data[0..32], v[0..32]);
}
+
+ #[test]
+ fn cursor_fill_buf_past_end() {
+ let data = [1, 2, 3];
+ let mut cursor = Cursor::new(&data);
+ cursor.set_position(10);
+
+ let buf = cursor.fill_buf().unwrap();
+ assert!(buf.is_empty());
+ }
+
+ #[test]
+ fn cursor_consume_past_end() {
+ let data = [1, 2, 3];
+ let mut cursor = Cursor::new(&data);
+ cursor.set_position(10);
+
+ cursor.consume(5);
+ assert_eq!(cursor.position(), 15);
+ }
}
Why this scored 15/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.