p2p: Error on decode for addresses > 512 bytes
What changed, and why it matters
This commit fixes a regression in the Bitcoin peer-to-peer address decoder. A recent rewrite accidentally stopped rejecting oversized network addresses (over 512 bytes), which could let malformed or unusually large data pass through as an unknown address type. The patch restores the original safety check that rejects such oversized inputs with an explicit error.
Review the decoder refactor for any other dropped validation checks, add regression tests for oversized AddrV2 address payloads, and consider fuzzing the P2P address decoding path.
Security signals we found
Input validation regression fixed
Restored length bound on deserialized address bytes
Potential DoS / resource consumption vector from oversized P2P address payloads
Behavioral compatibility fix to match previous implementation
Evidence from the diff
The AddrV2Decoder in p2p/src/address.rs previously used an ArrayDecoder + ByteVecDecoder that rejected address byte blobs larger than 512 bytes. After a refactor, the new decoder accepted any length and mapped oversized blobs to an unknown address type. The patch adds an explicit length check in end() returning AddrV2DecoderError::InvalidAddressLength when addr_bytes.len() > 512, restoring the prior behavior.
Changed components
p2p/src/address.rsAddrV2DecoderInspect captured patch +6 / −0
diff --git a/p2p/src/address.rs b/p2p/src/address.rs
index 9bd2a5ad..8e66ea7b 100644
--- a/p2p/src/address.rs
+++ b/p2p/src/address.rs
@@ -534,6 +534,12 @@ impl encoding::Decoder for AddrV2Decoder {
#[inline]
fn end(self) -> Result<Self::Output, Self::Error> {
let (net_type, addr_bytes) = self.0.end().map_err(AddrV2DecoderError::Decoder)?;
+ if addr_bytes.len() > 512 {
+ return Err(AddrV2DecoderError::InvalidAddressLength {
+ expected: 512,
+ got: addr_bytes.len(),
+ });
+ }
match u8::from_le_bytes(net_type) {
1 => {
let octets = Self::to_fixed_size_slice::<4>(addr_bytes)?;
Why this scored 47/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.