Skip to content

descriptor: reject trailing characters after the closing parenthesis - #858

Open
fametrano wants to merge 1 commit into
bitcoin-core:masterfrom
fametrano:btclib-666-reject-trailing
Open

fametrano wants to merge 1 commit into
bitcoin-core:masterfrom
fametrano:btclib-666-reject-trailing

Conversation

@fametrano

@fametrano fametrano commented Sep 8, 2026

Copy link
Copy Markdown
Contributor

_get_func_expr finds the closing parenthesis with rindex, but nothing checks that it is the final character, so trailing text after a descriptor's outer ) is silently dropped: pkh(<key>)garbage parses as pkh(<key>).

Bitcoin Core rejects trailing bytes — Func in src/script/parsing.cpp requires the closing parenthesis to be the span's last character. This makes _get_func_expr do the same, raising ValueError and naming the trailing text.

The checksum is stripped before parsing and _get_func_expr only ever receives a standalone func(...) expression, so no valid descriptor is affected; the existing tests pass unchanged, and a regression test covers a flat and a nested case.

The equivalent fix for Electrum, which shares this descriptor code, is spesmilo/electrum#10948.

_get_func_expr located the closing parenthesis with rindex but never
checked that it was the final character, so any content following it was
silently discarded and a descriptor such as pkh(<key>)garbage parsed as
pkh(<key>). Require the closing parenthesis to be the last character and
raise ValueError naming the trailing text otherwise, matching Bitcoin
Core's rejection of trailing bytes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant