fix(address): report decoded base58 payload length in error
What changed, and why it matters
This commit fixes a minor error-message bug. When a Bitcoin base58 address decoded to the wrong number of bytes, the error reported the length of the original string instead of the length of the decoded payload. The actual validation logic did not change; only the diagnostic detail is corrected.
No security action required. Treat as a normal bugfix or quality improvement.
Security signals we found
Error-reporting correction only
No change to validation or parsing logic
No cryptographic or address-acceptance behavior changed
Evidence from the diff
In bitcoin/src/address/mod.rs, the Address::from_str parsing path for legacy base58 addresses decodes the string and then tries to fit the decoded bytes into a 21-byte array. On failure it returns InvalidBase58PayloadLengthError. Previously the error’s length field was set to s.len() (the encoded string length). The patch changes it to data.len() (the decoded byte length). No bounds checks, memory safety, or consensus behavior changed.
Changed components
bitcoin/src/address/mod.rsLegacy base58 address parsing error pathInspect captured patch +3 / −2
diff --git a/bitcoin/src/address/mod.rs b/bitcoin/src/address/mod.rs
index 42d8f766..8a534002 100644
--- a/bitcoin/src/address/mod.rs
+++ b/bitcoin/src/address/mod.rs
@@ -919,8 +919,9 @@ impl Address<NetworkUnchecked> {
return Err(LegacyAddressTooLongError { length: s.len() }.into());
}
let data = base58::decode_check(s)?;
- let data: &[u8; 21] =
- (&*data).try_into().map_err(|_| InvalidBase58PayloadLengthError { length: s.len() })?;
+ let data: &[u8; 21] = (&*data)
+ .try_into()
+ .map_err(|_| InvalidBase58PayloadLengthError { length: data.len() })?;
let (prefix, &data) = data.split_first();
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.