What changed, and why it matters
This commit only adds two new automated tests for the block hash decoder. It does not change any production code, so it cannot introduce or fix a security vulnerability on its own.
No security action needed; treat as routine test-coverage improvement.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff adds unit tests in primitives/src/hash_types/block_hash.rs: one verifying the decoder read limit is 32 bytes, and another (std-only) verifying error display and source chaining when decoding ends prematurely on 31 bytes. No library logic is modified.
Changed components
primitives/src/hash_types/block_hash.rsInspect captured patch +30 / −0
diff --git a/primitives/src/hash_types/block_hash.rs b/primitives/src/hash_types/block_hash.rs
index ea0e35c0..fe063cb3 100644
--- a/primitives/src/hash_types/block_hash.rs
+++ b/primitives/src/hash_types/block_hash.rs
@@ -99,3 +99,33 @@ impl fmt::Display for BlockHashDecoderError {
impl std::error::Error for BlockHashDecoderError {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> { Some(&self.0) }
}
+
+#[cfg(test)]
+mod tests {
+ use encoding::Decoder as _;
+
+ use super::*;
+
+ #[test]
+ fn decoder_full_read_limit() {
+ assert_eq!(BlockHashDecoder::default().read_limit(), 32);
+ assert_eq!(<BlockHash as encoding::Decodable>::decoder().read_limit(), 32);
+ }
+
+ #[test]
+ #[cfg(feature = "std")]
+ fn decoder_error_display() {
+ use std::error::Error as _;
+ use std::string::ToString as _;
+
+ let mut decoder = BlockHashDecoder::new();
+ let mut bytes = &[0u8; 31][..];
+
+ assert!(decoder.push_bytes(&mut bytes).unwrap());
+
+ let err = decoder.end().unwrap_err();
+
+ assert!(!err.to_string().is_empty());
+ assert!(err.source().is_some());
+ }
+}
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.