Add test to kill mutant in decode_from_read
What changed, and why it matters
This commit only adds a new unit test to the codebase. It does not change any production code, fix a bug, or alter behavior. The test verifies that a decoding function correctly ignores extra bytes after the expected data when reading from a stream. There is no security issue present in the commit itself.
No action required. This is a test-only addition with no security relevance.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The commit adds decode_from_read_extra_data, a test mirroring existing tests decode_from_slice_extra_data and decode_from_read_unbuffered_extra_data. It checks that decode_from_read can decode a TestArray of four bytes from a six-byte cursor and that the trailing two bytes are ignored. No implementation code is modified.
Changed components
consensus_encoding/src/decode/mod.rs (tests only)Inspect captured patch +11 / −0
diff --git a/consensus_encoding/src/decode/mod.rs b/consensus_encoding/src/decode/mod.rs
index cc41fe83..38553043 100644
--- a/consensus_encoding/src/decode/mod.rs
+++ b/consensus_encoding/src/decode/mod.rs
@@ -315,6 +315,17 @@ mod tests {
assert_eq!(decoded.0, [1, 2, 3, 4]);
}
+ #[cfg(feature = "std")]
+ #[test]
+ fn decode_from_read_extra_data() {
+ let data = [1, 2, 3, 4, 5, 6];
+ let mut cursor = Cursor::new(&data);
+ let result: Result<TestArray, _> = decode_from_read(&mut cursor);
+ assert!(result.is_ok());
+ let decoded = result.unwrap();
+ assert_eq!(decoded.0, [1, 2, 3, 4]);
+ }
+
#[cfg(feature = "std")]
#[test]
fn decode_from_read_success() {
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.