This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: ipaddress module accepts octal formatted IPv4 addresses in IPv6 addresses
Type: behavior Stage: resolved
Components: Versions: Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: Julian, iritkatriel, ncoghlan, pitrou, pmoody, xZise
Priority: normal Keywords: patch

Created on 2014-08-27 09:33 by xZise, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
ipaddr.patch xZise, 2014-08-27 13:06 review
Messages (3)
msg225950 - (view) Author: Fabian (xZise) * Date: 2014-08-27 09:33
The ipaddress module accepts IPv6 addresses if the IPv4 address is formatted as an octal number, but http://tools.ietf.org/html/rfc3986#section-3.2.2 doesn't allow leading zeroes in the IPv4 address.

This is the current behaviour (in 3.4.1):

>>> ipaddress.ip_address("::1.0.0.00")
IPv6Address('::100:0')

Expected:

>>> ipaddress.ip_address("::1.0.0.00")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "3.4.1/lib/python3.4/ipaddress.py", line 54, in ip_address
    address)
ValueError: '::1.0.0.00' does not appear to be an IPv4 or IPv6 address

Because I didn't know it better, I first tried to patch the backport but this might be still applicable the official code: https://github.com/phihag/ipaddress/pull/12
msg225983 - (view) Author: Fabian (xZise) * Date: 2014-08-27 13:06
The patch adds an optional keyword which only accepts decimal numbers.
msg408058 - (view) Author: Irit Katriel (iritkatriel) * (Python committer) Date: 2021-12-09 00:24
This is what I get now on 3.11:


>>> ipaddress.ip_address("::1.0.0.00")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\User\src\cpython\Lib\ipaddress.py", line 54, in ip_address
    raise ValueError('%r does not appear to be an IPv4 or IPv6 address' %
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: '::1.0.0.00' does not appear to be an IPv4 or IPv6 address
History
Date User Action Args
2022-04-11 14:58:07adminsetgithub: 66478
2021-12-09 00:24:12iritkatrielsetstatus: open -> closed

nosy: + iritkatriel
messages: + msg408058

resolution: fixed
stage: resolved
2021-04-11 23:00:33Juliansetnosy: + Julian
2014-08-29 01:33:52berker.peksagsetnosy: + ncoghlan, pitrou, pmoody
2014-08-27 13:06:02xZisesetfiles: + ipaddr.patch
keywords: + patch
messages: + msg225983
2014-08-27 09:33:26xZisecreate