bd808 / python-iptools

A few useful functions and objects for manipulating ip addresses in python.
http://python-iptools.readthedocs.org/
BSD 2-Clause "Simplified" License
70 stars 17 forks source link

OverflowError when getting a list of addresses #12

Closed dreynolds closed 10 years ago

dreynolds commented 10 years ago

Using one of the IPv6 addresses from your example:

x = iptools.IpRangeList('fe80::/10')
print list(x)

Gives the following OverflowError:

Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/Users/david/.virtualenvs/env/lib/python2.6/site-packages/iptools/__init__.py", line 514, in __len__
    return sum([len(r) for r in self.ips])
OverflowError: long int too large to convert to int
bd808 commented 10 years ago

I can do some things to shove the site of the overflow around, but I don't think the code as written will execute cleanly no matter what I do. The IPv6 CIDR range that you picked (fe80::/10) contains 2118 IP addresses (332,306,998,946,228,968,225,951,765,070,086,144). Casting this to a list is likely to run into internal limits on list length in the python interpreter. In the Cpython interpreter the maximum list length is ((size_t)-1)>>1). On a 32-bit system this is: ((232)-1)>>1) == ((231)-1) == 21,474,83,647. A 64-bit system raises the limit to ((264)-1)>>1) == ((263)-1) == 9,223,372,036,854,775,807. By extension, to perform this particular operation successfully you will need a system where size_t > 2119.

dreynolds commented 10 years ago

Yeh, I wondered later if it was a system limitation :( Feel free to "wontfix" it if you like

On 1 Mar 2014, at 17:09, Bryan Davis notifications@github.com wrote:

I can do some things to shove the site of the overflow around, but I don't think the code as written will execute cleanly no matter what I do. The IPv6 CIDR range that you picked (fe80::/10) contains 2118 IP addresses (332,306,998,946,228,968,225,951,765,070,086,144). Casting this to a list is likely to run into internal limits on list length in the python interpreter. In the Cpython interpreter the maximum list length is ((size_t)-1)>>1). On a 32-bit system this is: ((232)-1)>>1) == ((231)-1) == 21,474,83,647. A 64-bit system raises the limit to ((264)-1)>>1) == ((263)-1) == 9,223,372,036,854,775,807. By extension, to perform this particular operation successfully you will need a system where size_t > 2119.

— Reply to this email directly or view it on GitHub.

bd808 commented 10 years ago

I was able to at least shove the problem out into the calling code.