Repository navigation
fix: decode ip6zone as length-prefixed, not a flag protocol (fixes #147) - #148
Merged
Merged
Conversation
…ltiformats#147) The utf8 codec (used only by ip6zone) declared SIZE = 0, which the framework treats as a value-less flag protocol. bytes_iter therefore read the zone's length byte as the next protocol code: /ip6zone/eth0 gained a phantom /ip4, and zones of other lengths (en0, wlan0) failed binary parsing. Use LENGTH_PREFIXED_VAR_SIZE, matching go-multiaddr. Re-enables the ip6zone QUIC cases that were commented out for 'binary encoding issues' and adds a regression test over en0/eth0/wlan0.
Now that ip6zone values decode from binary, a zone containing '/' would produce a text form that cannot be parsed back. Reject it in both directions, as go-multiaddr's ip6zoneVal does. Drop the stale IS_PATH comment and extend the multiformats#147 regression test to items() and transforms.string_to_bytes, which the issue also reported broken.
This was referenced Nov 18, 2026
Contributor
Author
|
Note on the red Tracked in #149, fixed by #150 (pins |
acul71
approved these changes
Nov 19, 2026
acul71
left a comment
Contributor
There was a problem hiding this comment.
Review
LGTM — solid, well-tested fix for #147.
What looks good
- Root cause is correct:
SIZE = 0madeip6zonea flag protocol, so the zone length byte was misread as the next protocol code (phantomip4foreth0, binary parse failures for other lengths). - Switching to
LENGTH_PREFIXED_VAR_SIZEmatches go-multiaddr and is scoped safely (utf8is only used byip6zone). - Slash rejection in both directions is the right go-parity guard for values that cannot round-trip in text form.
- Regression coverage is excellent: bytes round-trip,
protocols(),items(),value_for_protocol,split(),string_to_bytes, plus re-enabled QUIC+ip6zonecases that were previously disabled for this exact bug. - Newsfragment
147.bugfix.rstis correct. - After resync with #150, CI is fully green (core / lint / docs / windows).
Non-blocking notes
- Optional follow-up: tiny unit test for encode-path
"/"rejection on the codec, and/or a tracking issue for the broaderSIZE == 0vsSIZE < 0asymmetry called out in the PR.
Approved — ready to squash-merge.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What was wrong
multiaddr/codecs/utf8.py(used only byip6zone) setSIZE = 0, which the framework treats as a value-less flag protocol.bytes_to_stringhappened to read the length prefix anyway, sostr()looked correct, butbytes_iter(→protocols(),items(),split(),Multiaddr(bytes)) andstring_to_bytesdid not:/ip6zone/eth0/...→protocols()contained a phantomip4(length byte0x04==P_IP4),value_for_protocol("ip6zone")wasNone,split()raised./ip6zone/en0/...,/ip6zone/wlan0/...→Multiaddr(ma.to_bytes())raisedBinaryParseError(unknown protocol 3 / 5).Fix
SIZE = LENGTH_PREFIXED_VAR_SIZE, matching go-multiaddr (protoIP6ZONE,Size: LengthPrefixedVarSize)./in a zone value (both directions), as go-multiaddr'sip6zoneValdoes — otherwisestr()of such an address could not be parsed back.IS_PATHis set for ip6zone (it never is).Tests
test_ip6zone_value_is_length_prefixed[en0|eth0|wlan0]: bytes round-trip,protocols(),items(),value_for_protocol,split(), andtransforms.string_to_bytes— every symptom listed inip6zoneis decoded as a flag protocol: phantom/ip4, broken binary round-trip for zones ≠ 4 bytes #147.test_ip6zone_rejects_slash_in_binary_zone. Without the fix: en0/wlan0 fail parsing, eth0 fails on the phantomip4.ip6zoneQUIC cases intest_quic_validthat were commented out as "removed due to binary encoding issues in Python implementation" — they fail without this fix and pass with it.Notes
newsfragments/147.bugfix.rstadded;towncrier build --draftrenders it.pre-commit: all hooks pass exceptpyrefly-local, which also fails on unmodifiedmaster(451 errors with pyrefly 1.4.1, the unpinned latest). This branch adds no new pyrefly errors (451 → 451). Happy to open a separate issue about pinning pyrefly if useful.Out of scope (possible follow-ups)
SIZE <= 0whilebytes_iterreads one only forSIZE < 0; that asymmetry is what let a wrongSIZEsilently corrupt parsing. Keying flag protocols oncodec is Nonewould harden it.Multiaddr(bytes)validates framing only, not values, so malformed values surface atstr()time.to_stringstrips whitespace, so decode is lossy for zones with surrounding spaces.