python / python/cpython

ipaddress: IPv6Address.reverse_pointer produces an invalid name for an address with a scope id

Open
#155,836 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stdlib type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

Bug report

Since gh-88178 (a2104b7ce), :attr:~ipaddress.IPv6Address.exploded includes
the %scope_id suffix. IPv6Address._reverse_pointer derives the pointer
from self.exploded and only strips :, so the scope id is reversed into
the name:

>>> import ipaddress
>>> ipaddress.IPv6Address('fe80::1%eth0').reverse_pointer
'0.h.t.e.%.1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.e.f.ip6.arpa'

A scope id is link-local and is not part of the address, so it must not appear
in the reverse DNS name. The correct value is the one for fe80::1:

>>> ipaddress.IPv6Address('fe80::1').reverse_pointer
'1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.8.e.f.ip6.arpa'

Before a2104b7ce this raised :exc:~ipaddress.AddressValueError; it now returns
a malformed name silently.

Linked PRs
  • gh-155837

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at ipaddress.IPv6Address._reverse_pointer and the reverse_pointer examples in this report. Check how the scope_id suffix enters IPv6Address.exploded and verify the reverse DNS name for fe80::1%eth0 matches the unsuffixed address. Done means the scope identifier is absent from the generated pointer and the prior malformed output is covered by a regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
networking
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.