Skip to content

ipaddress.reverse_pointer returns nonsense if prefixed input is given #91601

Open

Description

@Zugschlus

Bug report

ipaddress.reverse_pointer does not seem to validate its input at all. For example:

$ python3
Python 3.10.4 (main, Apr  2 2022, 09:04:19) [GCC 11.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import ipaddress
>>> ipaddress.ip_network('2001:db8:1:2:3:4:5::/64',False).reverse_pointer
'4.6./.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.0.0.1.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa'
>>> 

This is very obviously wrong.

In this case of prefixed input, the output should be cut to the appropriate prefix length, yielding
2.0.0.0.1.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa as output. It is ok to assume /128 as the default, converting 2001:db8:1:2:3:4:5:: to 0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.0.0.1.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa, but input longer than that is an error.

Prefixed address strings are for example important when generating zone names for the server side of IPv6 reverse DNS. Run-of-the-mill network client software is unlikely to use this for addresses shorter than /128, but for the server side it is an important use case.

Greetings
Marc

Linked PRs

Activity

  1. added
    stdlibStandard Library Python modules in the Lib/ directory
    on Apr 16, 2022
  2. iacore commented on Nov 3, 2026

    @iacore

    Still reproducible on released versions, and the snippet in the report no longer runs as written.

    On 3.14.8 and 3.15.2, ipaddress.ip_network('2001:db8:1:2:3:4:5::/64') raises ValueError: 2001:db8:1:2:3:4:5:0/64 has host bits set, because strict defaults to true — so the exact example in the report errors out before reaching reverse_pointer.

    Going through ip_interface, the nonsense is unchanged on both versions:

    >>> ipaddress.ip_interface('2001:db8:1:2:3:4:5::/64').reverse_pointer
    '4.6./.0.0.0.0.5.0.0.0.4.0.0.0.3.0.0.0.2.0.0.0.1.0.0.0.8.b.d.0.1.0.0.2.ip6.arpa'
    

    The 4.6./. prefix is the artifact the report describes, and the interface still knows better: its .network is 2001:db8:1:2::/64, so the host bits are only kept in the address that reverse_pointer renders.

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

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions