mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-09-11 21:20:39 +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:
@@ -557,6 +557,14 @@ class PSBTTest(BitcoinTestFramework):
|
||||
|
||||
wallet.unloadwallet()
|
||||
|
||||
def test_decodepsbt_long_sighash_type(self):
|
||||
self.log.info("Test that decodepsbt rejects invalid trailing bytes in the sighash type field")
|
||||
node = self.nodes[0]
|
||||
psbt = PSBT.from_base64(node.createpsbt([{"txid": "00" * 32, "vout": 0}], [{"data": "00"}]))
|
||||
# The first byte of this sighash type is ALL, but the type itself is not
|
||||
psbt.i[0].map[PSBT_IN_SIGHASH_TYPE] = (0x101).to_bytes(4, "little")
|
||||
assert_equal(node.decodepsbt(psbt.to_base64())["inputs"][0]["sighash"], "")
|
||||
|
||||
def assert_change_type(self, psbtx, expected_type):
|
||||
"""Assert that the given PSBT has a change output with the given type."""
|
||||
|
||||
@@ -1619,6 +1627,7 @@ class PSBTTest(BitcoinTestFramework):
|
||||
if not self.options.usecli:
|
||||
self.test_sighash_mismatch()
|
||||
self.test_sighash_adding()
|
||||
self.test_decodepsbt_long_sighash_type()
|
||||
self.test_psbt_named_parameter_handling()
|
||||
self.test_psbt_roundtrip()
|
||||
self.test_psbt_version()
|
||||
|
||||
Reference in New Issue
Block a user