@@ -191,7 +191,6 @@ impl FromStr for DescriptorPublicKey {
191
191
let parent_fingerprint = bip32:: Fingerprint :: from_hex ( origin_id_hex) . map_err ( |_| {
192
192
DescriptorKeyParseError ( "Malformed master fingerprint, expected 8 hex chars" )
193
193
} ) ?;
194
-
195
194
let origin_path = raw_origin
196
195
. map ( |p| bip32:: ChildNumber :: from_str ( p) )
197
196
. collect :: < Result < bip32:: DerivationPath , bip32:: Error > > ( )
@@ -200,7 +199,6 @@ impl FromStr for DescriptorPublicKey {
200
199
} ) ?;
201
200
origin = Some ( ( parent_fingerprint, origin_path) ) ;
202
201
}
203
-
204
202
let key_part = if origin == None {
205
203
Ok ( s)
206
204
} else {
@@ -222,10 +220,18 @@ impl FromStr for DescriptorPublicKey {
222
220
} else {
223
221
let key = bitcoin:: PublicKey :: from_str ( key_part)
224
222
. 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
+ }
229
235
}
230
236
}
231
237
}
@@ -1502,6 +1508,15 @@ mod tests {
1502
1508
"Error while parsing simple public key"
1503
1509
) )
1504
1510
) ;
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
+ ) ;
1505
1520
}
1506
1521
1507
1522
#[ test]
0 commit comments