Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[3.14] gh-134062: Fix hash collisions in IPv4Network and IPv6Network (GH-134063)#134476

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
gpshead merged 1 commit intopython:3.14frommiss-islington:backport-f3fc0c1-3.14
May 22, 2025
Merged
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
gh-134062: Fix hash collisions in IPv4Network and IPv6Network (GH-134063
)(cherry picked from commitf3fc0c1)Co-authored-by: Mike Salvatore <mike.s.salvatore@gmail.com>gh-134062: Fix hash collisions in IPv4Network and IPv6Networkgh-134062: Add hash collision regression test
  • Loading branch information
@mssalvatore@miss-islington
mssalvatore authored andmiss-islington committedMay 22, 2025
commitfc67379dba2988a288c394e2eb809fb49eab7728
2 changes: 1 addition & 1 deletionLib/ipaddress.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -729,7 +729,7 @@ def __eq__(self, other):
returnNotImplemented

def__hash__(self):
returnhash(int(self.network_address)^int(self.netmask))
returnhash((int(self.network_address),int(self.netmask)))

def__contains__(self,other):
# always false if one is v4 and the other is v6.
Expand Down
28 changes: 28 additions & 0 deletionsLib/test/test_ipaddress.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2762,6 +2762,34 @@ def testV6HashIsNotConstant(self):
ipv6_address2=ipaddress.IPv6Interface("2001:658:22a:cafe:200:0:0:2")
self.assertNotEqual(ipv6_address1.__hash__(),ipv6_address2.__hash__())

# issue 134062 Hash collisions in IPv4Network and IPv6Network
deftestNetworkV4HashCollisions(self):
self.assertNotEqual(
ipaddress.IPv4Network("192.168.1.255/32").__hash__(),
ipaddress.IPv4Network("192.168.1.0/24").__hash__()
)
self.assertNotEqual(
ipaddress.IPv4Network("172.24.255.0/24").__hash__(),
ipaddress.IPv4Network("172.24.0.0/16").__hash__()
)
self.assertNotEqual(
ipaddress.IPv4Network("192.168.1.87/32").__hash__(),
ipaddress.IPv4Network("192.168.1.86/31").__hash__()
)

# issue 134062 Hash collisions in IPv4Network and IPv6Network
deftestNetworkV6HashCollisions(self):
self.assertNotEqual(
ipaddress.IPv6Network("fe80::/64").__hash__(),
ipaddress.IPv6Network("fe80::ffff:ffff:ffff:0/112").__hash__()
)
self.assertNotEqual(
ipaddress.IPv4Network("10.0.0.0/8").__hash__(),
ipaddress.IPv6Network(
"ffff:ffff:ffff:ffff:ffff:ffff:aff:0/112"
).__hash__()
)


if__name__=='__main__':
unittest.main()
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
:mod:`ipaddress`: fix collisions in :meth:`~object.__hash__` for
:class:`~ipaddress.IPv4Network` and :class:`~ipaddress.IPv6Network`
objects.
Loading

[8]ページ先頭

©2009-2025 Movatter.jp