Skip to content

Commit 77339c1

Browse files
authored
Merge pull request #187 from sanket1729/fuzz_desc
Fuzzer failure: hybrid keys
2 parents e36e089 + bd64ccc commit 77339c1

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/descriptor/mod.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,13 @@ impl FromStr for DescriptorPublicKey {
379379
is_wildcard,
380380
}))
381381
} else {
382+
if key_part.len() >= 2
383+
&& !(&key_part[0..2] == "02" || &key_part[0..2] == "03" || &key_part[0..2] == "04")
384+
{
385+
return Err(DescriptorKeyParseError(
386+
"Only publickeys with prefixes 02/03/04 are allowed",
387+
));
388+
}
382389
let key = bitcoin::PublicKey::from_str(key_part)
383390
.map_err(|_| DescriptorKeyParseError("Error while parsing simple public key"))?;
384391
Ok(DescriptorPublicKey::SinglePub(DescriptorSinglePub {
@@ -2406,6 +2413,15 @@ mod tests {
24062413
"Multiple \']\' in Descriptor Public Key"
24072414
))
24082415
);
2416+
2417+
// fuzz failure, hybrid keys
2418+
let desc = "0777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777";
2419+
assert_eq!(
2420+
DescriptorPublicKey::from_str(desc),
2421+
Err(DescriptorKeyParseError(
2422+
"Only publickeys with prefixes 02/03/04 are allowed"
2423+
))
2424+
);
24092425
}
24102426

24112427
#[test]

0 commit comments

Comments
 (0)