Skip to content

Commit 6a3f0f7

Browse files
committed
Merge #809: fix crash in Descriptor::parse_desc found by fuzzer
6bff186 add regression test for #806 (Andrew Poelstra) 05d3cc2 descriptor: fix key parsing error handling in parse_desc (Andrew Poelstra) Pull request description: Thanks to Bruno Garcia and i-am-yuvi who independently found this crash and reported it to me. Fixes #806 Needs backport. ACKs for top commit: brunoerg: code review ACK 6bff186; haven't tested i-am-yuvi: Tested and Code Review ACK 6bff186 sanket1729: ACK 6bff186 Tree-SHA512: abd386758fc6e2a408c2de7bb6be61274a4252cafd97130bd449ce2fb23180cffa416ffe7393a809c69cf541186f3866aaa9fef635ce57fbc4bcf455a5b287c0
2 parents 62d11df + 6bff186 commit 6a3f0f7

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

src/descriptor/mod.rs

+16-1
Original file line numberDiff line numberDiff line change
@@ -771,7 +771,7 @@ impl Descriptor<DescriptorPublicKey> {
771771
let descriptor = Descriptor::<String>::from_str(s)?;
772772
let descriptor = descriptor
773773
.translate_pk(&mut keymap_pk)
774-
.map_err(|e| e.expect_translator_err("No Outer context errors"))?;
774+
.map_err(TranslateErr::flatten)?;
775775

776776
Ok((descriptor, keymap_pk.0))
777777
}
@@ -2168,4 +2168,19 @@ pk(03f28773c2d975288bc7d1d205c3748651b075fbc6610e58cddeeddf8f19405aa8))";
21682168
Desc::from_str(&format!("tr({},pk({}))", x_only_key, uncomp_key)).unwrap_err();
21692169
Desc::from_str(&format!("tr({},pk({}))", x_only_key, x_only_key)).unwrap();
21702170
}
2171+
2172+
#[test]
2173+
fn regression_806() {
2174+
let secp = secp256k1::Secp256k1::signing_only();
2175+
type Desc = Descriptor<DescriptorPublicKey>;
2176+
// OK
2177+
Desc::from_str("pkh(111111111111111111111111111111110000008375319363688624584A111111)")
2178+
.unwrap_err();
2179+
// ERR: crashes in translate_pk
2180+
Desc::parse_descriptor(
2181+
&secp,
2182+
"pkh(111111111111111111111111111111110000008375319363688624584A111111)",
2183+
)
2184+
.unwrap_err();
2185+
}
21712186
}

src/lib.rs

+16-4
Original file line numberDiff line numberDiff line change
@@ -356,10 +356,22 @@ impl<E> TranslateErr<E> {
356356
///
357357
/// This function will panic if the Error is OutError.
358358
pub fn expect_translator_err(self, msg: &str) -> E {
359-
if let Self::TranslatorErr(v) = self {
360-
v
361-
} else {
362-
panic!("{}", msg)
359+
match self {
360+
Self::TranslatorErr(v) => v,
361+
Self::OuterError(ref e) => {
362+
panic!("Unexpected Miniscript error when translating: {}\nMessage: {}", e, msg)
363+
}
364+
}
365+
}
366+
}
367+
368+
impl TranslateErr<Error> {
369+
/// If we are doing a translation where our "outer error" is the generic
370+
/// Miniscript error, eliminate the `TranslateErr` type which is just noise.
371+
pub fn flatten(self) -> Error {
372+
match self {
373+
Self::TranslatorErr(e) => e,
374+
Self::OuterError(e) => e,
363375
}
364376
}
365377
}

0 commit comments

Comments
 (0)