Strings of intergers from "1000" to "9999" return an IPv4Address object

24 views
Skip to first unread message

mathershifter

unread,
Jun 29, 2012, 12:37:06 PM6/29/12
to ipaddr...@googlegroups.com
I was expecting all of seemingly invalid addresses to raise an exception.

Examples:

Python 2.6.5 (r265:79063, Feb 28 2011, 21:55:45)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-50)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ipaddress
>>>
>>> ipaddress.IPv4Address('999')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/site-packages/ipaddress.py", line 1259, in __init__
    self._ip = self._ip_int_from_string(addr_str)
  File "/usr/lib/python2.6/site-packages/ipaddress.py", line 1067, in _ip_int_from_string
    raise AddressValueError(ip_str)
ipaddress.AddressValueError: 999
>>>
>>> ipaddress.IPv4Address('1000')
IPv4Address('49.48.48.48')
>>>
>>> ipaddress.IPv4Address('5000')
IPv4Address('53.48.48.48')
>>>
>>> ipaddress.IPv4Address('9999')
IPv4Address('57.57.57.57')
>>>
>>> ipaddress.IPv4Address('10000')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.6/site-packages/ipaddress.py", line 1259, in __init__
    self._ip = self._ip_int_from_string(addr_str)
  File "/usr/lib/python2.6/site-packages/ipaddress.py", line 1067, in _ip_int_from_string
    raise AddressValueError(ip_str)
ipaddress.AddressValueError: 10000

Peter Moody

unread,
Jun 29, 2012, 12:54:46 PM6/29/12
to mathershifter, ipaddr...@googlegroups.com
Interesting. Looks like the string is being interpreted as bytes.

>>> isinstance('1000', bytes)
True
>>> isinstance('1000', str)
True

and since it's four characters long, it's passing the test on line 1245.

I'll get a quick fix out for this.

Thanks!
--
Peter Moody      Google    1.650.253.7306
Security Engineer  pgp:0xC3410038

Peter Moody

unread,
Jun 29, 2012, 1:01:29 PM6/29/12
to mathershifter, ipaddr...@googlegroups.com
should be fixed in 7d8873212f94.

Thanks again for reporting this.

Cheers,
peter

mathershifter

unread,
Jun 29, 2012, 1:26:27 PM6/29/12
to ipaddr...@googlegroups.com, mathershifter
and thanks for fixing. :)
Reply all
Reply to author
Forward
0 new messages