wire: add test for IPv4-mapped IPv6 address in NetAddressV2FromBytes
What changed, and why it matters
This commit only adds a new unit test to btcd's networking code. It checks that a special IPv6 address format (the IPv4-mapped IPv6 address ::ffff:127.0.0.1) is correctly treated as an IPv4 address. There is no code change that fixes or changes behavior; it only adds a test verifying existing behavior.
No action required. This is a test-only commit. If reviewing a related security issue, look for a separate production-code commit that changes NetAddressV2FromBytes behavior; this commit alone does not alter runtime behavior.
Security signals we found
No strong security signals were identified.
Evidence from the diff
The diff adds one test case in wire/netaddressv2_test.go for NetAddressV2FromBytes. The test feeds a 16-byte IPv4-mapped IPv6 address (0x00…0x00 0xff 0xff 127.0.0.1) and asserts the function returns an IPv4 NetAddress with network ID 0x01 (ipv4) and string ‘127.0.0.1’. No production code is modified. The commit message frames this as ensuring IPv4-mapped IPv6 addresses are converted to IPv4, but the actual change is test-only.
Changed components
wire/netaddressv2_test.goInspect captured patch +11 / −0
diff --git a/wire/netaddressv2_test.go b/wire/netaddressv2_test.go
index 8aea5c8..d9e7819 100644
--- a/wire/netaddressv2_test.go
+++ b/wire/netaddressv2_test.go
@@ -95,6 +95,17 @@ func TestNetAddressV2FromBytes(t *testing.T) {
string(ipv6),
},
+ // IPv4-mapped IPv6 encoding (::ffff:127.0.0.1) should be
+ // converted to IPv4.
+ {
+ []byte{
+ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
+ 0x00, 0x00, 0xff, 0xff, 0x7f, 0x00, 0x00, 0x01,
+ },
+ "127.0.0.1",
+ string(ipv4),
+ },
+
// OnionCat encoding
{
[]byte{
Why this scored 12/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.