AI-generated analysisPublished automatically and not human-verified. Validated context appears in community notes below.
← Watch feed
Moderate 59 Bitcoin

p2p: Wrap NetworkMessageDecoder to check payload len

Public commit record

What the developer wrote

Authored by Mitchell Bagot

73/100 · Adequate
p2p: Wrap NetworkMessageDecoder to check payload len

In the old implementation of the NetworkMessage decoding, the true
payload length was checked against the claimed value specified in the
message header. The new version does not do so.

Add PayloadLengthMismatch error variation for
V1NetworkMessageDecoderError.
Rename NetworkMessageDecoder to NetworkMessageDecoderInner and add a
wrapper that checks the payload length against the provided value in
the constructor.
✓ Specific, descriptive subject✓ Names a concrete action or component✓ Provides detailed explanatory context
The short version

What changed, and why it matters

This commit fixes a regression in the Bitcoin peer-to-peer message decoder. The old decoder verified that the number of bytes actually decoded matched the payload length declared in the message header, but a newer implementation skipped that check. The patch reintroduces the check by wrapping the inner decoder: it now counts consumed bytes and returns a new 'PayloadLengthMismatch' error if the decoded length does not match the header's claim. Without this check, a malformed or malicious message could be accepted even if its actual contents did not match the announced size, potentially causing parsing confusion or protocol issues.

Recommended action

Treat as a security-relevant correctness fix. Review whether the prior lack of length validation could have enabled denial-of-service or parsing-confusion attacks, and consider adding regression tests for payload length mismatch cases. Update dependency consumers to a release containing this commit.

Security signals we found

01

Restored payload length validation against message header claim

02

New explicit error variant for length mismatch

03

Prevents acceptance of messages whose decoded payload length differs from declared length

04

Regression from older implementation that performed this check

05

read_limit capping reduces over-reading beyond declared payload size

Risk score

Why this scored 59/100

Our methodology →
Potential impact 18/30
Exploitability 12/25
Stealth signal 8/15
Affected reach 10/15
Confidence 7/10
Evidence quality 4/5
Human-validated context

Community notes

Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.

No validated notes yet.

The AI analysis stands alone for now. Submit a note if you can add evidence or important context.