What changed, and why it matters
This commit only adds a new automated test. It does not change any production code, fix a bug, or alter behavior. The test checks that when a Bitcoin address has an invalid payload length, the error message reports the actual decoded payload size (22 bytes) rather than the length of the base58-encoded string. There is no security issue in this change itself.
No security action needed. Review the test for correctness and merge if it matches the intended behavior.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff adds a single unit test in bitcoin/src/address/mod.rs named base58_invalid_payload_length_reports_decoded_size. The test constructs a 22-byte base58check payload (invalid because P2PKH payloads must be 21 bytes), encodes it, parses it with Address::from_base58_str, and asserts that the resulting InvalidBase58PayloadLength error carries the decoded payload length (22), not the encoded string length. No library code is modified.
Changed components
bitcoin/src/address/mod.rs (tests only)Inspect captured patch +18 / −0
diff --git a/bitcoin/src/address/mod.rs b/bitcoin/src/address/mod.rs
index 8a534002..196f74ad 100644
--- a/bitcoin/src/address/mod.rs
+++ b/bitcoin/src/address/mod.rs
@@ -1603,4 +1603,22 @@ mod tests {
assert!(address.is_spend_standard());
assert_eq!(address.address_type(), Some(AddressType::P2a));
}
+
+ #[test]
+ fn base58_invalid_payload_length_reports_decoded_size() {
+ use crate::constants::PUBKEY_ADDRESS_PREFIX_MAIN;
+
+ let mut payload = [0u8; 22]; // Invalid: should be 21
+ payload[0] = PUBKEY_ADDRESS_PREFIX_MAIN;
+ let encoded = base58::encode_check(&payload);
+
+ let err = Address::<NetworkUnchecked>::from_base58_str(&encoded).unwrap_err();
+ match err {
+ Base58Error::InvalidBase58PayloadLength(inner) => {
+ assert_eq!(inner.invalid_base58_payload_length(), 22); // Payload size
+ assert_ne!(inner.invalid_base58_payload_length(), encoded.len()); // Not string size
+ }
+ other => panic!("unexpected error: {other:?}"),
+ }
+ }
}
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.