Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gracefully handle ZEROFILL flag when given a IPv6 address #383

Closed
kennell opened this issue May 12, 2024 · 3 comments · Fixed by #384
Closed

Gracefully handle ZEROFILL flag when given a IPv6 address #383

kennell opened this issue May 12, 2024 · 3 comments · Fixed by #384

Comments

@kennell
Copy link

kennell commented May 12, 2024

I am in the process of upgrading netaddr from 0.10.1 to 1.2.1, my Python version is 3.12.3.

In older versions the netaddr.ZEROFILL flag was ignored when a IPv6 address was given:

# netaddr==0.10.1
>>> import netaddr
>>> ip = netaddr.IPAddress('2600:1f18:631e:2f85:93a9:f7b0:d18:89a7', flags=netaddr.ZEROFILL)
>>> ip
IPAddress('2600:1f18:631e:2f85:93a9:f7b0:d18:89a7')

In the current release it throws an ValueError:

# netaddr==1.2.1
>>> import netaddr
>>> ip = netaddr.IPAddress('2600:1f18:631e:2f85:93a9:f7b0:d18:89a7', flags=netaddr.ZEROFILL)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/homebrew/lib/python3.12/site-packages/netaddr/ip/__init__.py", line 333, in __init__
    self._value = module.str_to_int(addr, flags)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/lib/python3.12/site-packages/netaddr/strategy/ipv4.py", line 120, in str_to_int
    addr = '.'.join(['%d' % int(i) for i in addr.split('.')])
                            ^^^^^^
ValueError: invalid literal for int() with base 10: '2600:1f18:631e:2f85:93a9:f7b0:d18:89a7'

Suggestion: ignore the netaddr.ZEROFILL flag when a IPv6 is given.

@kennell kennell changed the title Gracefully handle ZEROFILL flag when given a IPv6 addresse Gracefully handle ZEROFILL flag when given a IPv6 address May 12, 2024
@jstasiak
Copy link
Contributor

Hi, thank you for reporting this and providing all the information. Definitely not intended and I'll fix it when I get to another round of patches (hopefully soon).

@kennell
Copy link
Author

kennell commented May 12, 2024

Thank you for the swift reply; greatly appreciate your work on this package.

jstasiak added a commit that referenced this issue May 20, 2024
It was a regression, affected IPAddress.

Fixes: d39b7d1 ("Handle IP parsing errors more precisely")
Resolves: #383
jstasiak added a commit that referenced this issue May 20, 2024
It was a regression, affected IPAddress.

Fixes: d39b7d1 ("Handle IP parsing errors more precisely")
Resolves: #383
@jstasiak
Copy link
Contributor

Thank you for the kind words. The fix for this has been released in netaddr 1.3.0.

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 a pull request may close this issue.

2 participants