Skip to content

Commit 3bf002c

Browse files
committed
add regression test for #806
When parsing a descriptor with `Descriptor::parse_descriptor`, we first parse as a string and then parse the keys. We fail to consider parsing errors in the keys, resulting in a panic. Also, clean up the panic message so it's clearer what's going on.
1 parent 4f8b065 commit 3bf002c

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

src/descriptor/mod.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2050,4 +2050,19 @@ pk(03f28773c2d975288bc7d1d205c3748651b075fbc6610e58cddeeddf8f19405aa8))";
20502050
Desc::from_str(&format!("tr({},pk({}))", x_only_key, uncomp_key)).unwrap_err();
20512051
Desc::from_str(&format!("tr({},pk({}))", x_only_key, x_only_key)).unwrap();
20522052
}
2053+
2054+
#[test]
2055+
fn regression_806() {
2056+
let secp = secp256k1::Secp256k1::signing_only();
2057+
type Desc = Descriptor<DescriptorPublicKey>;
2058+
// OK
2059+
Desc::from_str("pkh(111111111111111111111111111111110000008375319363688624584A111111)")
2060+
.unwrap_err();
2061+
// ERR: crashes in translate_pk
2062+
Desc::parse_descriptor(
2063+
&secp,
2064+
"pkh(111111111111111111111111111111110000008375319363688624584A111111)",
2065+
)
2066+
.unwrap_err();
2067+
}
20532068
}

src/lib.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -340,10 +340,11 @@ impl<E> TranslateErr<E> {
340340
///
341341
/// This function will panic if the Error is OutError.
342342
pub fn expect_translator_err(self, msg: &str) -> E {
343-
if let Self::TranslatorErr(v) = self {
344-
v
345-
} else {
346-
panic!("{}", msg)
343+
match self {
344+
Self::TranslatorErr(v) => v,
345+
Self::OuterError(ref e) => {
346+
panic!("Unexpected Miniscript error when translating: {}\nMessage: {}", e, msg)
347+
}
347348
}
348349
}
349350
}

0 commit comments

Comments
 (0)