Skip to content

Commit 9cbb637

Browse files
authored
Merge pull request #203 from ElementsProject/2024-06--pegin-parse
transaction: range-check pegin data when parsing
2 parents a7c5013 + 639c964 commit 9cbb637

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/transaction.rs

+20
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,9 @@ impl<'tx> PeginData<'tx> {
436436
if pegin_witness.len() != 6 {
437437
return Err("size not 6");
438438
}
439+
if pegin_witness[5].len() < 80 {
440+
return Err("merkle proof too short");
441+
}
439442

440443
Ok(PeginData {
441444
outpoint: prevout,
@@ -2379,4 +2382,21 @@ mod tests {
23792382
Err(encode::Error::ParseFailed("superfluous asset issuance")),
23802383
));
23812384
}
2385+
2386+
#[test]
2387+
fn malformed_pegin() {
2388+
let mut input: TxIn = hex_deserialize!("\
2389+
0004000000000000ffffffff0000040000c0c0c0c0c0c0c0c0c0000000000000\
2390+
00805555555555555505c0c0c0c0c03fc0c0c0c0c0c0c0c0c0c0c0c00200ff01\
2391+
0000000000fd0000000000000000010000000000ffffffffffffffff00000000\
2392+
000000ff000000000000010000000000000000000001002d342d35313700\
2393+
");
2394+
input.witness = hex_deserialize!("\
2395+
0000000608202020202020202020202020202020202020202020202020202020\
2396+
2020202020202020202020202020202020202020202020202020202020202020\
2397+
2020202020202020202020202020202020202020202020202020202020200000\
2398+
00000000000000000000000000000002000400000000\
2399+
");
2400+
assert!(input.pegin_data().is_none());
2401+
}
23822402
}

0 commit comments

Comments
 (0)