Use write! in UnknownAddressTypeError display
What changed, and why it matters
This commit fixes a bug where displaying a specific error message in Bitcoin address parsing could cause the program to crash with a stack overflow. The crash only happens in 'no_std' builds (a special configuration without the standard library). The fix replaces an incorrect macro with the correct one so the error message is shown without trying to endlessly include itself as its own source.
Apply the patch and audit other Display implementations for similar misuse of write_err! where no source error exists, especially in no_std code paths. Consider adding a regression test that formats UnknownAddressTypeError in a no_std build.
Security signals we found
Denial of service via stack overflow
Infinite recursion in error Display implementation
no_std-specific vulnerability
Error-handling path triggered by malformed/unrecognized address type input
Evidence from the diff
The Display implementation for UnknownAddressTypeError in bitcoin/src/address/error.rs used write_err! macro, which is meant to attach a source error. Because UnknownAddressTypeError has no source, write_err! in no_std environments recursively tried to display self as its own source, causing infinite recursion and a stack overflow. The patch changes write_err! to write!, which simply formats the message without source chaining, eliminating the recursion.
Changed components
bitcoin/src/address/error.rsUnknownAddressTypeErrorno_std builds of rust-bitcoinInspect captured patch +1 / −1
diff --git a/bitcoin/src/address/error.rs b/bitcoin/src/address/error.rs
index 34a5d37b..fdd33c7a 100644
--- a/bitcoin/src/address/error.rs
+++ b/bitcoin/src/address/error.rs
@@ -62,7 +62,7 @@ pub struct UnknownAddressTypeError(pub String);
impl fmt::Display for UnknownAddressTypeError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
- write_err!(f, "failed to parse {} as address type", self.0; self)
+ write!(f, "failed to parse {} as address type", self.0)
}
}
Why this scored 35/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.