mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-09-16 08:16:38 +02:00
psbt: fix rendering for invalid long sighash type field
The PSBT sighash type field is a 32 bit unsigned integer in BIP 174, signed in PSBTInput, and it is not validated when deserialized. decodepsbt incorrectly truncates this field before looking up its name. Fix that and add a test.
This commit is contained in:
@@ -338,9 +338,13 @@ const std::map<unsigned char, std::string> mapSigHashTypes = {
|
||||
{static_cast<unsigned char>(SIGHASH_SINGLE|SIGHASH_ANYONECANPAY), std::string("SINGLE|ANYONECANPAY")},
|
||||
};
|
||||
|
||||
std::string SighashToStr(unsigned char sighash_type)
|
||||
std::string SighashToStr(int32_t sighash_type)
|
||||
{
|
||||
const auto& it = mapSigHashTypes.find(sighash_type);
|
||||
// Signatures encode the sighash type in a single byte, but the PSBT field
|
||||
// for it is a 32 bit unsigned integer in BIP 174 (signed in PSBTInput)
|
||||
if (sighash_type < 0 || sighash_type > 0xff) return "";
|
||||
const uint8_t sighash_byte(sighash_type);
|
||||
const auto& it = mapSigHashTypes.find(sighash_byte);
|
||||
if (it == mapSigHashTypes.end()) return "";
|
||||
return it->second;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user