Skip to content

decode scoped IPv6 addresses instead of rejecting them#324

Merged
agronholm merged 2 commits into
agronholm:masterfrom
sahvx655-wq:ipv6-scoped-address-decode
Jul 4, 2026
Merged

decode scoped IPv6 addresses instead of rejecting them#324
agronholm merged 2 commits into
agronholm:masterfrom
sahvx655-wq:ipv6-scoped-address-decode

Conversation

@sahvx655-wq

Copy link
Copy Markdown
Contributor

Changes

A scoped IPv6 address survives encoding but blows up on the way back in. encode_ipv6_address serialises an IPv6Address that carries a scope_id as the tag 54 array [address, null, zone id], but decode_ipv6 only recognised the [prefix, address] network form and the [address, prefix] interface form. The null second element falls straight through to the catch-all, so loads(dumps(IPv6Address("fe80::1%eth0"))) raises CBORDecodeError: invalid types in input array rather than returning the address. Anything holding a link-local address with a zone id therefore cannot be round-tripped, and the failure is silent until you actually feed such a value back through the decoder.

I hoisted the zone id suffix formatting above the type match (it is common to every array form) and added a branch that reads a null second element with a bytes first element as a bare scoped address, constructing the IPv6Address with the %zone suffix directly instead of routing it through the network/interface class. The network and interface paths, including the over-length address check, are untouched.

Checklist

  • You've added tests (in tests/) which would fail without your patch
  • You've updated the documentation (in docs/), in case of behavior changes or new features
  • You've added a new changelog entry (in docs/versionhistory.rst).

@sahvx655-wq sahvx655-wq force-pushed the ipv6-scoped-address-decode branch from ff5cc58 to 11c1c2f Compare July 2, 2026 09:20
@coveralls

coveralls commented Jul 2, 2026

Copy link
Copy Markdown

Coverage Status

coverage: 94.682% (+0.008%) from 94.674% — sahvx655-wq:ipv6-scoped-address-decode into agronholm:master

@agronholm agronholm merged commit 00e3dea into agronholm:master Jul 4, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants