Skip to content

ip6zone is decoded as a flag protocol: phantom /ip4, broken binary round-trip for zones ≠ 4 bytes #147

Closed

Description

@yashksaini-coder

Summary

multiaddr/codecs/utf8.py (used only by ip6zone) sets SIZE = 0. Elsewhere in the codebase SIZE == 0 means "flag protocol, no value", while variable-length codecs use LENGTH_PREFIXED_VAR_SIZE (-1). bytes_to_string happens to read the length prefix anyway, so str() looks fine, but bytes_iter (and therefore protocols(), items(), split(), Multiaddr(bytes)), string_to_bytes, and MultiAddrItems treat the zone as valueless.

Reproduction (master @ e232e2b)

from multiaddr import Multiaddr
m = Multiaddr("/ip6zone/eth0/ip6/fe80::1/tcp/80")
[p.name for p in m.protocols()]   # ['ip6zone', 'ip4', 'ip6', 'tcp']   <- phantom ip4 ("eth0" read as 101.116.104.48)
m.value_for_protocol("ip6zone")   # None
m.split()                          # BinaryParseError

Multiaddr(Multiaddr("/ip6zone/en0/ip6/fe80::1").to_bytes())    # BinaryParseError: protocol 3: Unknown Protocol
Multiaddr(Multiaddr("/ip6zone/wlan0/ip6/fe80::1").to_bytes())  # BinaryParseError: protocol 5: Unknown Protocol
# "eth0" only works because its length byte 0x04 == P_IP4

multiaddr.transforms.string_to_bytes("/ip6zone/eth0/ip6/fe80::1") drops the zone value entirely (b'*)\xfe\x80...').

Expected

Same as go-multiaddr, where ip6zone is Size: LengthPrefixedVarSize (protocols.go).

Proposed fix

SIZE = LENGTH_PREFIXED_VAR_SIZE in codecs/utf8.py. Locally this makes every case above correct and the existing suite still passes (429 passed, 1 skipped). Would add regression tests for zones of length ≠ 4 (en0, wlan0) covering protocols(), value_for_protocol, split() and the bytes round-trip, and re-enable the commented-out ip6zone cases at tests/test_multiaddr.py:177-178 if they pass.

Happy to open the PR.

Activity

  1. added a commit that references this issue on Nov 23, 2026
    c3e3d6d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions