psbt: Avoid unsigned int overflow in PSBT_IN_TAP_BIP32_DERIVATION

This commit is contained in:
Andrew Chow
2022-08-09 17:20:23 -04:00
parent ac59112a6a
commit 70a55c059b
3 changed files with 13 additions and 0 deletions

View File

@ -641,6 +641,9 @@ struct PSBTInput
s >> leaf_hashes;
size_t after_hashes = s.size();
size_t hashes_len = before_hashes - after_hashes;
if (hashes_len > value_len) {
throw std::ios_base::failure("Input Taproot BIP32 keypath has an invalid length");
}
size_t origin_len = value_len - hashes_len;
m_tap_bip32_paths.emplace(xonly, std::make_pair(leaf_hashes, DeserializeKeyOrigin(s, origin_len)));
break;