Merge bitcoin/bitcoin#31603: descriptor: check whitespace in keys within fragments

21e9d39a37 docs: add release notes for 31603 (brunoerg)
a8b548d75d test: `getdescriptorinfo`/`importdescriptors` with whitespace in pubkeys (brunoerg)
c7afca3d62 test: descriptor: check whitespace into keys (brunoerg)
cb722a3cea descriptor: check whitespace in ParsePubkeyInner (brunoerg)
50856695ef test: fix descriptors in `ismine_tests` (brunoerg)

Pull request description:

  Currently, we successfully parse descriptors which contains spaces in the beginning or end of the public/private key within a fragment (e.g. `pk( KEY)`, `pk(KEY )` or `pk( KEY )`). I have noticed that one of the reasons is that the `DecodeBase58` function simply ignore these whitespaces.

  This PR changes the `ParsePubkeyInner ` to reject pubkeys that contain a whitespace at the beginning and/or at the end. We will only check the whitespace in some RPCs (e.g. `importdescriptors`), but an already imported descriptor won't be affected by this check, especially because we store descriptors from `ToString`.

  For context: https://github.com/brunoerg/bitcoinfuzz/issues/72

ACKs for top commit:
  rkrux:
    tACK 21e9d39a37
  darosior:
    re-ACK 21e9d39a37
  sipa:
    utACK 21e9d39a37

Tree-SHA512: 54f48a89a235517e5cdc29a46dceeb7dabbee93c7616a166288ff3f90131808eb0ece43b0797a11fe827a5f7bd51d65e3e75c16789b0a42020934cabb684cc8f
This commit is contained in:
Ryan Ofsky
2025-03-18 08:07:32 -04:00
6 changed files with 41 additions and 5 deletions

View File

@@ -128,6 +128,20 @@ class ImportDescriptorsTest(BitcoinTestFramework):
assert_equal(info["ismine"], True)
assert_equal(info["ischange"], True)
self.log.info("Should not import a descriptor with an invalid public key due to whitespace")
self.test_importdesc({"desc": descsum_create("pkh( " + key.pubkey + ")"),
"timestamp": "now",
"internal": True},
error_code=-5,
error_message=f"pkh(): Key ' {key.pubkey}' is invalid due to whitespace",
success=False)
self.test_importdesc({"desc": descsum_create("pkh(" + key.pubkey + " )"),
"timestamp": "now",
"internal": True},
error_code=-5,
error_message=f"pkh(): Key '{key.pubkey} ' is invalid due to whitespace",
success=False)
# # Test importing of a P2SH-P2WPKH descriptor
key = get_generate_key()
self.log.info("Should not import a p2sh-p2wpkh descriptor without checksum")