Skip to content

Commit 28c4f39

Browse files
Check bounds in verify_full function to prevent panics (#62)
1 parent f6e4f4d commit 28c4f39

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/verify.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,19 @@ pub fn verify_full(
7474
verify_full_p2tr(address, message, to_sign, pub_key)
7575
}
7676
AddressData::Segwit { witness_program }
77-
if witness_program.version().to_num() == 0 && witness_program.program().len() == 20 =>
77+
if witness_program.version().to_num() == 0
78+
&& witness_program.program().len() == 20
79+
&& !to_sign.input.is_empty()
80+
&& to_sign.input[0].witness.len() > 1 =>
7881
{
7982
let pub_key =
8083
PublicKey::from_slice(&to_sign.input[0].witness[1]).map_err(|_| Error::InvalidPublicKey)?;
8184

8285
verify_full_p2wpkh(address, message, to_sign, pub_key, false)
8386
}
84-
AddressData::P2sh { script_hash: _ } => {
87+
AddressData::P2sh { script_hash: _ }
88+
if !to_sign.input.is_empty() && to_sign.input[0].witness.len() > 1 =>
89+
{
8590
let pub_key =
8691
PublicKey::from_slice(&to_sign.input[0].witness[1]).map_err(|_| Error::InvalidPublicKey)?;
8792

0 commit comments

Comments
 (0)