From bbe87eccf2b9f01295e3c94a06130c6e7ac9bfa4 Mon Sep 17 00:00:00 2001 From: Martin Habovstiak Date: Wed, 5 Mar 2025 13:05:04 +0100 Subject: [PATCH] Fix bug in PSBT `Deserialize` for `XOnlyPublicKey` During upgrade of `secp256k1` a number of function calls needed to be rewritten to not use `from_slice` but `from_byte_array`. Unfortunately, the conversion wasn't correct and caused panics on invalid inputs rather than errors. This fixes it simply by calling `try_into` on the entire slice and converting the error. --- bitcoin/src/psbt/serialize.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bitcoin/src/psbt/serialize.rs b/bitcoin/src/psbt/serialize.rs index 26bfc9b32..b21a5ac0c 100644 --- a/bitcoin/src/psbt/serialize.rs +++ b/bitcoin/src/psbt/serialize.rs @@ -261,7 +261,7 @@ impl Serialize for XOnlyPublicKey { impl Deserialize for XOnlyPublicKey { fn deserialize(bytes: &[u8]) -> Result { XOnlyPublicKey::from_byte_array( - bytes[..32].try_into().expect("statistically impossible to hit"), + bytes.try_into().map_err(|_| Error::InvalidXOnlyPublicKey)?, ) .map_err(|_| Error::InvalidXOnlyPublicKey) }