Skip to content

Commit c585c27

Browse files
committed
Merge #814: Backport #809 to 0.10.x
06400b1 bump patch version of 10.2 (Andrew Poelstra) 1fed0ec add regression test for #806 (Andrew Poelstra) 2f21e23 descriptor: fix key parsing error handling in parse_desc (Andrew Poelstra) 0e40319 ci: update CI job to run all the fuzz tests (Andrew Poelstra) 6ff58af lib: remove some deny lints (Andrew Poelstra) Pull request description: Backports #809 to 10.x. This is a direct rebase of #810 except that I added a commit with some lint fixes. (I had been avoiding this, but we've been having a lot of backports lately so I think I ought to just address it.) After this I will do 11.x. ACKs for top commit: sanket1729: utACK 06400b1 Tree-SHA512: 6a30480becf20aa64e1f4528cf0d1df75bd2ddbaad95ae6bd4a3f5885624a791c7d7a77020b27675c348b2ff95467e0cb8bb42ca2c58112d7322f75480608dca
2 parents 53d61f6 + 06400b1 commit c585c27

File tree

6 files changed

+59
-34
lines changed

6 files changed

+59
-34
lines changed

.github/workflows/fuzz.yml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ jobs:
1616
fail-fast: false
1717
matrix:
1818
fuzz_target: [
19-
roundtrip_miniscript_str,
20-
roundtrip_miniscript_script,
19+
compile_descriptor,
2120
parse_descriptor,
22-
roundtrip_semantic,
2321
parse_descriptor_secret,
24-
roundtrip_descriptor,
2522
roundtrip_concrete,
26-
compile_descriptor,
23+
roundtrip_descriptor,
24+
roundtrip_miniscript_script,
25+
roundtrip_miniscript_str,
26+
roundtrip_semantic,
2727
]
2828
steps:
2929
- name: Install test dependencies

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "miniscript"
3-
version = "10.2.0"
3+
version = "10.2.1"
44
authors = ["Andrew Poelstra <[email protected]>, Sanket Kanjalkar <[email protected]>"]
55
license = "CC0-1.0"
66
homepage = "https://github.com/rust-bitcoin/rust-miniscript/"

fuzz/Cargo.toml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,33 +15,33 @@ miniscript = { path = "..", features = [ "compiler" ] }
1515
regex = "1.4"
1616

1717
[[bin]]
18-
name = "roundtrip_miniscript_str"
19-
path = "fuzz_targets/roundtrip_miniscript_str.rs"
20-
21-
[[bin]]
22-
name = "roundtrip_miniscript_script"
23-
path = "fuzz_targets/roundtrip_miniscript_script.rs"
18+
name = "compile_descriptor"
19+
path = "fuzz_targets/compile_descriptor.rs"
2420

2521
[[bin]]
2622
name = "parse_descriptor"
2723
path = "fuzz_targets/parse_descriptor.rs"
2824

29-
[[bin]]
30-
name = "roundtrip_semantic"
31-
path = "fuzz_targets/roundtrip_semantic.rs"
32-
3325
[[bin]]
3426
name = "parse_descriptor_secret"
3527
path = "fuzz_targets/parse_descriptor_secret.rs"
3628

29+
[[bin]]
30+
name = "roundtrip_concrete"
31+
path = "fuzz_targets/roundtrip_concrete.rs"
32+
3733
[[bin]]
3834
name = "roundtrip_descriptor"
3935
path = "fuzz_targets/roundtrip_descriptor.rs"
4036

4137
[[bin]]
42-
name = "roundtrip_concrete"
43-
path = "fuzz_targets/roundtrip_concrete.rs"
38+
name = "roundtrip_miniscript_script"
39+
path = "fuzz_targets/roundtrip_miniscript_script.rs"
4440

4541
[[bin]]
46-
name = "compile_descriptor"
47-
path = "fuzz_targets/compile_descriptor.rs"
42+
name = "roundtrip_miniscript_str"
43+
path = "fuzz_targets/roundtrip_miniscript_str.rs"
44+
45+
[[bin]]
46+
name = "roundtrip_semantic"
47+
path = "fuzz_targets/roundtrip_semantic.rs"

fuzz/fuzz-util.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
REPO_DIR=$(git rev-parse --show-toplevel)
44

5+
# Sort order is effected by locale. See `man sort`.
6+
# > Set LC_ALL=C to get the traditional sort order that uses native byte values.
7+
export LC_ALL=C
8+
59
listTargetFiles() {
610
pushd "$REPO_DIR/fuzz" > /dev/null || exit 1
7-
find fuzz_targets/ -type f -name "*.rs"
11+
find fuzz_targets/ -type f -name "*.rs" | sort
812
popd > /dev/null || exit 1
913
}
1014

src/descriptor/mod.rs

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -695,12 +695,9 @@ impl Descriptor<DescriptorPublicKey> {
695695
}
696696

697697
let descriptor = Descriptor::<String>::from_str(s)?;
698-
let descriptor = descriptor.translate_pk(&mut keymap_pk).map_err(|e| {
699-
Error::Unexpected(
700-
e.expect_translator_err("No Outer context errors")
701-
.to_string(),
702-
)
703-
})?;
698+
let descriptor = descriptor
699+
.translate_pk(&mut keymap_pk)
700+
.map_err(TranslateErr::flatten)?;
704701

705702
Ok((descriptor, keymap_pk.0))
706703
}
@@ -2037,4 +2034,19 @@ pk(03f28773c2d975288bc7d1d205c3748651b075fbc6610e58cddeeddf8f19405aa8))";
20372034
Desc::from_str(&format!("tr({},pk({}))", x_only_key, uncomp_key)).unwrap_err();
20382035
Desc::from_str(&format!("tr({},pk({}))", x_only_key, x_only_key)).unwrap();
20392036
}
2037+
2038+
#[test]
2039+
fn regression_806() {
2040+
let secp = secp256k1::Secp256k1::signing_only();
2041+
type Desc = Descriptor<DescriptorPublicKey>;
2042+
// OK
2043+
Desc::from_str("pkh(111111111111111111111111111111110000008375319363688624584A111111)")
2044+
.unwrap_err();
2045+
// ERR: crashes in translate_pk
2046+
Desc::parse_descriptor(
2047+
&secp,
2048+
"pkh(111111111111111111111111111111110000008375319363688624584A111111)",
2049+
)
2050+
.unwrap_err();
2051+
}
20402052
}

src/lib.rs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,6 @@
8181
#![deny(non_camel_case_types)]
8282
#![deny(non_snake_case)]
8383
#![deny(unused_mut)]
84-
#![deny(dead_code)]
85-
#![deny(unused_imports)]
86-
#![deny(missing_docs)]
8784

8885
#[cfg(target_pointer_width = "16")]
8986
compile_error!(
@@ -394,10 +391,22 @@ impl<E> TranslateErr<E> {
394391
///
395392
/// This function will panic if the Error is OutError.
396393
pub fn expect_translator_err(self, msg: &str) -> E {
397-
if let Self::TranslatorErr(v) = self {
398-
v
399-
} else {
400-
panic!("{}", msg)
394+
match self {
395+
Self::TranslatorErr(v) => v,
396+
Self::OuterError(ref e) => {
397+
panic!("Unexpected Miniscript error when translating: {}\nMessage: {}", e, msg)
398+
}
399+
}
400+
}
401+
}
402+
403+
impl TranslateErr<Error> {
404+
/// If we are doing a translation where our "outer error" is the generic
405+
/// Miniscript error, eliminate the `TranslateErr` type which is just noise.
406+
pub fn flatten(self) -> Error {
407+
match self {
408+
Self::TranslatorErr(e) => e,
409+
Self::OuterError(e) => e,
401410
}
402411
}
403412
}

0 commit comments

Comments
 (0)