DecodeTxErr: prevent potential DoS caused by a malformed tx or block - #5
Open
ronny wants to merge 1 commit into
Open
DecodeTxErr: prevent potential DoS caused by a malformed tx or block#5ronny wants to merge 1 commit into
ronny wants to merge 1 commit into
Conversation
SomeoneWeird
requested review from
DivineGod,
elusiveshiba,
raffecat and
tjstebbing
May 19, 2026 14:08
DivineGod
approved these changes
May 19, 2026
A malformed tx or block with a varint count claiming more entries than the remaining buffer could possibly encode (e.g. a 0xff prefix declaring max-uint64 inputs) would make readVinVout/readBlock/readMerkleBranch loop billions of times against an exhausted stream, growing slices of zero-valued records until OOM. Recover() in consumers can't catch this — the goroutine never panics, it just never returns. Add tight lower-bound size constants (minTxInBytes=41, minTxOutBytes=9, minTxBytes=60, minHashBytes=32) and reject any varint count that would exceed remaining-bytes / min-per-element. Applied at every varint-driven loop in block.go: tx_count, merkle-branch hashes, vin_count, vout_count, and the witness stack count + per-item length. TestDecodeTxErr_MaliciousVinCount covers both the huge-varint case and the truncated-count case under a 500ms deadline, so a regression fails the test instead of hanging CI.
ronny
force-pushed
the
fix-decode-tx-malformed-input
branch
from
May 20, 2026 02:38
52b3f39 to
ee83c3f
Compare
Contributor
Author
|
@raffecat @SomeoneWeird could either of you please merge if this is good to go? I don't have access. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A malformed tx or block with a varint count claiming more entries than the remaining buffer could possibly encode (e.g. a
0xffprefix declaring max-uint64 inputs) would makereadVinVout/readBlock/readMerkleBranchloop billions of times against an exhausted stream, growing slices of zero-valued records until OOM.recover()in consumers can't catch this — the goroutine never panics, it just never returns.This change adds tight lower-bound size constants (
minTxInBytes=41,minTxOutBytes=9,minTxBytes=60,minHashBytes=32) and rejects any varint count that would exceed remaining-bytes / min-per-element. Applied at every varint-driven loop in block.go:tx_count, merkle-branch hashes,vin_count,vout_count, and the witness stack count + per-item length.TestDecodeTxErr_MaliciousVinCountcovers both the huge-varint case and the truncated-count case under a 500ms deadline, so a regression fails the test instead of hanging CI.