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

Appearance settings

gh-128840: Limit the number of parts in IPv6 address parsing #128841

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

Merged
merged 9 commits into from
May 24, 2025
Merged
Show file tree
Hide file tree
Changes from 4 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
7 changes: 5 additions & 2 deletions 7 Lib/ipaddress.py
Original file line number Diff line number Diff line change
Expand Up @@ -1661,7 +1661,11 @@ def _ip_int_from_string(cls, ip_str):
if not ip_str:
raise AddressValueError('Address cannot be empty')

parts = ip_str.split(':')
# We want to allow more parts than the max to be 'split'
# to preserve the correct error message when there are
# too many parts combined with '::'
_max_parts = cls._HEXTET_COUNT + 1
parts = ip_str.split(':', maxsplit=_max_parts)

# An IPv6 address needs at least 2 colons (3 parts).
_min_parts = 3
Expand All @@ -1681,7 +1685,6 @@ def _ip_int_from_string(cls, ip_str):
# An IPv6 address can't have more than 8 colons (9 parts).
# The extra colon comes from using the "::" notation for a single
# leading or trailing zero part.
_max_parts = cls._HEXTET_COUNT + 1
if len(parts) > _max_parts:
msg = "At most %d colons permitted in %r" % (_max_parts-1, ip_str)
raise AddressValueError(msg)
Expand Down
2 changes: 2 additions & 0 deletions 2 Lib/test/test_ipaddress.py
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,8 @@ def assertBadSplit(addr):
assertBadSplit("8:7:6:5:4:3:2:1::%scope")
# A trailing IPv4 address is two parts
assertBadSplit("10:9:8:7:6:5:4:3:42.42.42.42%scope")
# Long IPv6 address
assertBadSplit(("0:" * 10000) + "0")

def test_bad_address_split_v6_too_many_parts(self):
def assertBadSplit(addr):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Limit the number of splitting on colons (``:``) that will occur while parsing
gpshead marked this conversation as resolved.
Show resolved Hide resolved
an IPv6 address. This prevents excessive memory consumption and potential
denial-of-service when parsing a large IPv6 address.
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.