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.12] gh-128840: Fix parsing long IPv6 addresses with embedded IPv4 address (GH-134836)#134847

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

Open
miss-islington wants to merge1 commit intopython:3.12
base:3.12
Choose a base branch
Loading
frommiss-islington:backport-d83576b-3.12
Open
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
10 changes: 6 additions & 4 deletionsLib/ipaddress.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1664,10 +1664,12 @@ def _ip_int_from_string(cls, ip_str):
"""
if not ip_str:
raise AddressValueError('Address cannot be empty')
if len(ip_str) > 39:
msg = ("At most 39 characters expected in "
f"{ip_str[:14]!r}({len(ip_str)-28} chars elided){ip_str[-14:]!r}")
raise AddressValueError(msg)
if len(ip_str) > 45:
shorten = ip_str
if len(shorten) > 100:
shorten = f'{ip_str[:45]}({len(ip_str)-90} chars elided){ip_str[-45:]}'
raise AddressValueError(f"At most 45 characters expected in "
f"{shorten!r}")

# We want to allow more parts than the max to be 'split'
# to preserve the correct error message when there are
Expand Down
19 changes: 17 additions & 2 deletionsLib/test/test_ipaddress.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -391,14 +391,16 @@ def assertBadSplit(addr):

def test_bad_address_split_v6_too_long(self):
def assertBadSplit(addr):
msg = r"At most39 characters expected in %s"
with self.assertAddressError(msg,repr(re.escape(addr[:14]))):
msg = r"At most45 characters expected in'%s"
with self.assertAddressError(msg, re.escape(addr[:45])):
ipaddress.IPv6Address(addr)

# Long IPv6 address
long_addr = ("0:" * 10000) + "0"
assertBadSplit(long_addr)
assertBadSplit(long_addr + "%zoneid")
assertBadSplit(long_addr + ":255.255.255.255")
assertBadSplit(long_addr + ":ffff:255.255.255.255")

def test_bad_address_split_v6_too_many_parts(self):
def assertBadSplit(addr):
Expand DownExpand Up@@ -2170,6 +2172,11 @@ def testIPv6AddressTooLarge(self):
self.assertEqual(ipaddress.ip_address('FFFF::192.0.2.1'),
ipaddress.ip_address('FFFF::c000:201'))

self.assertEqual(ipaddress.ip_address('0000:0000:0000:0000:0000:FFFF:192.168.255.255'),
ipaddress.ip_address('::ffff:c0a8:ffff'))
self.assertEqual(ipaddress.ip_address('FFFF:0000:0000:0000:0000:0000:192.168.255.255'),
ipaddress.ip_address('ffff::c0a8:ffff'))

self.assertEqual(ipaddress.ip_address('::FFFF:192.0.2.1%scope'),
ipaddress.ip_address('::FFFF:c000:201%scope'))
self.assertEqual(ipaddress.ip_address('FFFF::192.0.2.1%scope'),
Expand All@@ -2182,6 +2189,10 @@ def testIPv6AddressTooLarge(self):
ipaddress.ip_address('::FFFF:c000:201%scope'))
self.assertNotEqual(ipaddress.ip_address('FFFF::192.0.2.1'),
ipaddress.ip_address('FFFF::c000:201%scope'))
self.assertEqual(ipaddress.ip_address('0000:0000:0000:0000:0000:FFFF:192.168.255.255%scope'),
ipaddress.ip_address('::ffff:c0a8:ffff%scope'))
self.assertEqual(ipaddress.ip_address('FFFF:0000:0000:0000:0000:0000:192.168.255.255%scope'),
ipaddress.ip_address('ffff::c0a8:ffff%scope'))

def testIPVersion(self):
self.assertEqual(self.ipv4_address.version, 4)
Expand DownExpand Up@@ -2585,6 +2596,10 @@ def testCompressIPv6Address(self):
'::7:6:5:4:3:2:0': '0:7:6:5:4:3:2:0/128',
'7:6:5:4:3:2:1::': '7:6:5:4:3:2:1:0/128',
'0:6:5:4:3:2:1::': '0:6:5:4:3:2:1:0/128',
'0000:0000:0000:0000:0000:0000:255.255.255.255': '::ffff:ffff/128',
'0000:0000:0000:0000:0000:ffff:255.255.255.255': '::ffff:255.255.255.255/128',
'ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255':
'ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff/128',
}
for uncompressed, compressed in list(test_addresses.items()):
self.assertEqual(compressed, str(ipaddress.IPv6Interface(
Expand Down
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
Fix parsing long IPv6 addresses with embedded IPv4 address.
Loading

[8]ページ先頭

©2009-2025 Movatter.jp