Skip to content

fix(dash): reject headers messages above Core's batch limit - #1140

Merged
xdustinface merged 1 commit into
devfrom
fix/headers-decode-prealloc
Oct 8, 2026
Merged

xdustinface merged 1 commit into
devfrom
fix/headers-decode-prealloc

Conversation

@ZocoLini

@ZocoLini ZocoLini commented Oct 7, 2026 •

Copy link
Copy Markdown
Collaborator

Closes #1124.

The headers decoder reserved space for up to 16384 headers from the peer-controlled count before reading any, so a few-byte frame with a huge count triggered a ~1.3 MB allocation. headers2 had the same pattern, capped at MAX_VEC_SIZE.

Core never sends more than 2000 headers in headers or 8000 in headers2 (MAX_HEADERS_UNCOMPRESSED_RESULT / MAX_HEADERS_COMPRESSED_RESULT in src/validation.h) and treats more as misbehaviour (net_processing.cpp). Both decoders now reject larger counts before reserving, which also bounds the allocation.

For headers2, Core's limit is 2000 unless the negotiated protocol version allows 8000. The decoder doesn't know the negotiated version, so it enforces the absolute maximum.

Testing

  • Unit (test_case): exactly the limit decodes and one above is rejected, for both messages. A frame carrying only a u64::MAX count fails.
  • cargo test -p dashcore, cargo test -p dash-spv and -p dash-spv-ffi --test dashd_sync with dashd integration tests, clippy -D warnings.

test-case is added to dash's dev-dependencies (same version as dash-spv, hashes, key-wallet).

🤖 Generated with Claude Code

PR Hygiene · 499f8d1

  • Bots — coderabbitai skipped after its own rate limit
  • Self-review — post /self-reviewed
  • Build green
  • Approvals
    • files with no dedicated owner (dash/Cargo.toml, dash/src/network/message.rs, dash/src/network/message_headers2.rs) — QuantumExplorer or xdustinface

When every merge requirement is met, the PR Hygiene check passes. Reviewer limits do not block merging; other required GitHub checks and protections still apply.

The `headers` decoder reserved space for up to 16384 headers from the
peer-controlled count before reading any, so a few-byte frame with a huge
count triggered a ~1.3 MB allocation. `headers2` did the same, capped at
`MAX_VEC_SIZE`.

Core never sends more than 2000 headers in `headers` or 8000 in
`headers2` (`MAX_HEADERS_UNCOMPRESSED_RESULT` and
`MAX_HEADERS_COMPRESSED_RESULT`) and treats more as misbehaviour. Reject
larger counts before reserving, which also bounds the allocation.

Closes #1124

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@coderabbitai

coderabbitai Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 28 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

⚙️ Run configuration
  • Configuration used: Repository: dashpay/rust-dashcore/.coderabbit.yaml
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0ac30a58-a63f-46dc-94e7-aa081ac133eb
📥 Commits

Reviewing files that changed from the base of the PR and between 67b307c and 499f8d1.

📒 Files selected for processing (3)
  • dash/Cargo.toml
  • dash/src/network/message.rs
  • dash/src/network/message_headers2.rs
  • Autopilot · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

Waiting for bot review — coderabbitai not yet. Wait for the missing reviews, or a writer can post /skip-bots to proceed without them; blocking findings still need addressing.
Full checklist in the description.

@github-actions github-actions Bot added the waiting-bots Waiting for the review bots to report on this head label Oct 7, 2026
@codecov

codecov Bot commented Oct 7, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 77.92%. Comparing base (67b307c) to head (499f8d1).

Additional details and impacted files
@@            Coverage Diff             @@
##              dev    #1140      +/-   ##
==========================================
- Coverage   77.92%   77.92%   -0.01%     
==========================================
  Files         302      302              
  Lines       79108    79143      +35     
==========================================
+ Hits        61644    61669      +25     
- Misses      17464    17474      +10     
Flag Coverage Δ
core 75.01% <100.00%> (+0.04%) ⬆️
ffi 51.15% <ø> (ø)
rpc 48.95% <ø> (ø)
spv 92.35% <ø> (-0.05%) ⬇️
wallet 81.99% <ø> (ø)
Files with missing lines Coverage Δ
dash/src/network/message.rs 87.06% <100.00%> (+0.37%) ⬆️
dash/src/network/message_headers2.rs 88.21% <100.00%> (+0.43%) ⬆️

... and 6 files with indirect coverage changes

@github-actions

github-actions Bot commented Oct 7, 2026 •

Copy link
Copy Markdown
Contributor

Bots are done — your move: post /self-reviewed.
Full checklist in the description.

@github-actions github-actions Bot added waiting-self-review Waiting for the author to post /self-reviewed bot-review-skipped A required review bot did not report; it was skipped by the window or by a person. and removed waiting-bots Waiting for the review bots to report on this head labels Oct 7, 2026
@xdustinface
xdustinface merged commit 644d373 into dev Oct 8, 2026
36 of 37 checks passed
@xdustinface
xdustinface deleted the fix/headers-decode-prealloc branch October 8, 2026 05:54
xdustinface pushed a commit that referenced this pull request Oct 21, 2026
The `headers` decoder reserved space for up to 16384 headers from the
peer-controlled count before reading any, so a few-byte frame with a huge
count triggered a ~1.3 MB allocation. `headers2` did the same, capped at
`MAX_VEC_SIZE`.

Core never sends more than 2000 headers in `headers` or 8000 in
`headers2` (`MAX_HEADERS_UNCOMPRESSED_RESULT` and
`MAX_HEADERS_COMPRESSED_RESULT`) and treats more as misbehaviour. Reject
larger counts before reserving, which also bounds the allocation.

Closes #1124

Co-authored-by: Claude Opus 5.5 <[email protected]>
(cherry picked from commit 644d373)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bot-review-skipped A required review bot did not report; it was skipped by the window or by a person. waiting-self-review Waiting for the author to post /self-reviewed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

dash: avoid count-driven preallocation when decoding headers

2 participants