Add test case to prevent regressions to Witness FromIterator
What changed, and why it matters
This commit only adds a new automated test. It does not change any production code. The test checks that building a Witness from a very long iterator (over 4 million empty byte slices) does not accidentally drop elements. It is a regression test following an earlier fix, not a security patch itself.
No action required; treat as routine test coverage. Review the prior fix commit if assessing the underlying issue.
Security signals we found
Regression test for prior Witness::from_iter length handling
No production code changes
Evidence from the diff
The diff adds a single unit test, from_iter_does_not_silently_lose_elements, in primitives/src/witness.rs. The test creates a Witness by collecting an iterator of 4,000,001 empty &[u8] references and asserts the resulting Witness length equals 4,000,001. No library code is modified. The commit message explicitly states this is a regression test added after a previous fix.
Changed components
primitives/src/witness.rs (test module only)Inspect captured patch +11 / −0
diff --git a/primitives/src/witness.rs b/primitives/src/witness.rs
index 16d23db7..2995c179 100644
--- a/primitives/src/witness.rs
+++ b/primitives/src/witness.rs
@@ -1314,6 +1314,17 @@ mod test {
assert!(witness4.is_empty());
}
+ #[test]
+ fn from_iter_does_not_silently_lose_elements() {
+ let n: usize = 4_000_001;
+ let witness: Witness = core::iter::repeat(&[0u8; 0]).take(n).collect();
+ let len = witness.len();
+ assert_eq!(
+ len, n,
+ "from_iter silently produced a witness with {len} elements (expected {n})"
+ );
+ }
+
#[test]
#[cfg(feature = "hex")]
fn test_from_hex() {
Why this scored 12/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.