[New-bugs-announce] [issue20446] ipaddress: hash similarities for ipv4 and ipv6

flambda report at bugs.python.org
Thu Jan 30 14:02:08 CET 2014

New submission from flambda:


I am a bit unsure if this is a problem but bear with me:

Using ipaddress I noticed that: 
hash(ipaddress.ip_address("")) == hash(ipaddress.ip_address("::1"))

which makes sense as ipaddress uses this:
    def __hash__(self):
        return hash(hex(int(self._ip)))
as the hash.

This means that in a mixed environment (ipv4 and ipv6 addresses), hashtables with hash(hex(int(b))), int(b)<2**32 will be filled more then tables with int(b)>2**32 due to the ipv4 and ipv6 address space overlapping in the first 32bits.

If this is intended behaviour, I am sorry to have bothered you.
Have a nice evening.

components: Interpreter Core
messages: 209714
nosy: flambda
priority: normal
severity: normal
status: open
title: ipaddress: hash similarities for ipv4 and ipv6
type: behavior
versions: Python 3.3

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list