bitcoin: Remove FromHex usage in serde code
What changed, and why it matters
This is a small maintenance patch that changes how hex decoding errors are reported during serialization/deserialization. It removes usage of a now-inaccessible error-detail API from the `hex` crate and instead reports the error's display message. There is no indication this fixes an exploitable vulnerability; it is a compatibility and cleanup change.
No security action required. Treat as routine dependency-compatibility maintenance. Review updated serde error messages for usability if desired.
Security signals we found
No security-relevant signals in commit message or diff
Change is driven by upstream API breakage, not a vulnerability report
Error-handling simplification in serde deserialization path
Evidence from the diff
The commit updates bitcoin/src/consensus/serde.rs to stop relying on hex crate error internals (FromHex/DecodeInitError length field and DecodeError::invalid_char()), which were hidden in a stable hex release. Error conversion now uses serde::de::Error::custom(self.0) for both DecodeInitError and DecodeError. This is a compile-time/API compatibility fix with a minor user-visible change in serde error messages.
Changed components
bitcoin/src/consensus/serde.rsHex deserialization error reportingInspect captured patch +2 / −9
diff --git a/bitcoin/src/consensus/serde.rs b/bitcoin/src/consensus/serde.rs
index 6a7fc22e..7b6529d3 100644
--- a/bitcoin/src/consensus/serde.rs
+++ b/bitcoin/src/consensus/serde.rs
@@ -137,20 +137,13 @@ pub mod hex {
impl super::IntoDeError for DecodeInitError {
fn into_de_error<E: serde::de::Error>(self) -> E {
- E::invalid_length(self.0.length(), &"an even number of ASCII-encoded hex digits")
+ serde::de::Error::custom(self.0)
}
}
impl super::IntoDeError for DecodeError {
fn into_de_error<E: serde::de::Error>(self) -> E {
- use serde::de::Unexpected;
-
- const EXPECTED_CHAR: &str = "an ASCII-encoded hex digit";
-
- match self.0.invalid_char() {
- c if c.is_ascii() => E::invalid_value(Unexpected::Char(c as _), &EXPECTED_CHAR),
- c => E::invalid_value(Unexpected::Unsigned(c.into()), &EXPECTED_CHAR),
- }
+ serde::de::Error::custom(self.0)
}
}
}
Why this scored 19/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.