Skip to content

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

Merged
f321x merged 1 commit into
spesmilo:masterfrom
fametrano:btclib-666-reject-trailing
Oct 6, 2026
Merged

f321x merged 1 commit into
spesmilo: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. _get_func_expr only ever receives a standalone func(...) expression. So no valid descriptor is affected, and the existing tests pass unchanged. A regression test covers a flat and a nested case.

The same fix for HWI, which shares this descriptor code, is bitcoin-core/HWI#858.

Written with LLM, a computer and the Internet; the mistakes, as usual, are all mine.

The parser located a descriptor's closing parenthesis with rindex but
did not verify it was the final character, so trailing bytes after it
were silently discarded and pkh(<key>)garbage was accepted as
pkh(<key>). Require the closing parenthesis to end the expression and
raise ValueError naming the trailing text.
@fametrano
fametrano force-pushed the btclib-666-reject-trailing branch from aa36f01 to 37e9671 Compare September 27, 2026 23:02
@fametrano

Copy link
Copy Markdown
Contributor Author

Sorry, I rebased #10948, #10951 and #10952 onto current master, which put their tests and regtest runs back into approval. All three were green before the rebase. Could a maintainer approve the runs and take a look when there's time?

@f321x

f321x commented Oct 6, 2026

Copy link
Copy Markdown
Member

Bitcoin Core rejects trailing bytes — Func in src/script/parsing.cpp requires the closing parenthesis to be the span's last character.

https://github.com/bitcoin/bitcoin/blob/3cb91bc7da67158fe6dc79886239f867245f1158/src/script/parsing.cpp#L22-L29

Thanks.

@f321x
f321x merged commit dc83e13 into spesmilo:master Oct 6, 2026
11 checks passed
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.

2 participants