Skip to content

Commit f305198

Browse files
committed
Fix fuzzer failure
1 parent eae1634 commit f305198

File tree

1 file changed

+21
-6
lines changed

1 file changed

+21
-6
lines changed

src/descriptor/mod.rs

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,6 @@ impl FromStr for DescriptorPublicKey {
191191
let parent_fingerprint = bip32::Fingerprint::from_hex(origin_id_hex).map_err(|_| {
192192
DescriptorKeyParseError("Malformed master fingerprint, expected 8 hex chars")
193193
})?;
194-
195194
let origin_path = raw_origin
196195
.map(|p| bip32::ChildNumber::from_str(p))
197196
.collect::<Result<bip32::DerivationPath, bip32::Error>>()
@@ -200,7 +199,6 @@ impl FromStr for DescriptorPublicKey {
200199
})?;
201200
origin = Some((parent_fingerprint, origin_path));
202201
}
203-
204202
let key_part = if origin == None {
205203
Ok(s)
206204
} else {
@@ -222,10 +220,18 @@ impl FromStr for DescriptorPublicKey {
222220
} else {
223221
let key = bitcoin::PublicKey::from_str(key_part)
224222
.map_err(|_| DescriptorKeyParseError("Error while parsing simple public key"))?;
225-
Ok(DescriptorPublicKey::SinglePub(DescriptorSinglePub {
226-
key,
227-
origin,
228-
}))
223+
// There should not be any leading information following SinglePublickey.
224+
// Origin None case is dealt directly
225+
if origin.is_some() && parts.next().is_some() {
226+
Err(DescriptorKeyParseError(
227+
"Multiple ']' in Descriptor Public Key",
228+
))
229+
} else {
230+
Ok(DescriptorPublicKey::SinglePub(DescriptorSinglePub {
231+
key,
232+
origin,
233+
}))
234+
}
229235
}
230236
}
231237
}
@@ -1502,6 +1508,15 @@ mod tests {
15021508
"Error while parsing simple public key"
15031509
))
15041510
);
1511+
1512+
// fuzzer errors
1513+
let desc = "[11111f11]033333333333333333333333333333323333333333333333333333333433333333]]333]]3]]101333333333333433333]]]10]333333mmmm";
1514+
assert_eq!(
1515+
DescriptorPublicKey::from_str(desc),
1516+
Err(DescriptorKeyParseError(
1517+
"Multiple \']\' in Descriptor Public Key"
1518+
))
1519+
);
15051520
}
15061521

15071522
#[test]

0 commit comments

Comments
 (0)