What changed, and why it matters
This commit adds a check in btcd's Bitcoin network message parser to reject v2 protocol messages that contain leftover, unread data after the expected payload has been decoded. Previously, extra bytes at the end of a message payload were silently ignored. This could allow malformed or padded messages to be accepted, potentially causing inconsistent parsing between btcd and other Bitcoin node software, which in turn could be abused to split the peer-to-peer network or evade message-size limits.
Treat as a low-to-moderate security hardening patch. Review whether similar trailing-byte checks are needed in v1 message decoding and other protocol parsers. Backport to maintained release branches if v2 message support is present. No immediate emergency response is indicated, but nodes should upgrade to ensure consistent protocol behavior.
Security signals we found
Strict input validation added to network protocol parser
Rejection of trailing bytes prevents parsing ambiguity
Potential P2P protocol malleability vector addressed
Defensive hardening of v2 message decoding path
Evidence from the diff
In wire/message.go, ReadV2MessageN now verifies that the temporary buffer is fully consumed after decoding a v2 message. If bytes remain, it returns a messageError. This prevents trailing data in v2 message payloads from being silently discarded. The change is defensive: it aligns btcd with strict payload-length enforcement and mitigates risks such as ambiguous message parsing, malleability, or resource-accounting discrepancies where trailing bytes could be used to pad messages without affecting their semantic interpretation.
Changed components
wire/message.goReadV2MessageN functionBitcoin v2 P2P message decodingInspect captured patch +6 / −0
diff --git a/wire/message.go b/wire/message.go
index 73bae42..40edb96 100644
--- a/wire/message.go
+++ b/wire/message.go
@@ -570,6 +570,12 @@ func ReadV2MessageN(plaintext []byte, pver uint32, enc MessageEncoding) (
return nil, nil, err
}
+ if buf.Len() > 0 {
+ str := fmt.Sprintf("message payload has %d extra bytes "+
+ "after decode", buf.Len())
+ return nil, nil, messageError("ReadV2MessageN", str)
+ }
+
return msg, plaintext, nil
}
Why this scored 49/100
Community notes
Notes can correct, qualify, or add evidence to the AI analysis. Every note shown here has been validated by a human moderator.
The AI analysis stands alone for now. Submit a note if you can add evidence or important context.