Skip to content

Commit 4559a5e

Browse files
Address review comments.
1 parent 0a33a89 commit 4559a5e

File tree

2 files changed

+7
-6
lines changed

2 files changed

+7
-6
lines changed

Lib/http/client.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@
113113

114114
# Data larger than this will be read in chunks, to prevent extreme
115115
# overallocation.
116-
_SAFE_BUF_SIZE = 1 << 20
116+
_MIN_READ_BUF_SIZE = 1 << 20
117117

118118

119119
# Header name/value ABNF (http://tools.ietf.org/html/rfc7230#section-3.2)
@@ -647,11 +647,13 @@ def _safe_read(self, amt):
647647
reading. If the bytes are truly not available (due to EOF), then the
648648
IncompleteRead exception can be used to detect the problem.
649649
"""
650-
cursize = min(amt, _SAFE_BUF_SIZE)
650+
cursize = min(amt, _MIN_READ_BUF_SIZE)
651651
data = self.fp.read(cursize)
652652
while len(data) < amt:
653653
if len(data) < cursize:
654654
raise IncompleteRead(data, amt-len(data))
655+
# This is a geometric increase in read size (never more than
656+
# doubling out the current length of data per loop iteration).
655657
delta = min(cursize, amt - cursize)
656658
data += self.fp.read(cursize)
657659
cursize += delta
Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
Fix a potential denial of service in the :mod:`http.client` module.
1+
Fix a potential memory denial of service in the :mod:`http.client` module.
22
When connecting to a malicious server, it could cause
33
an arbitrary amount of memory to be allocated.
4-
In best case this could lead to a :exc:`MemoryError` or other process crash.
5-
In worst case it could lead to swapping which would dramatically slow down the
6-
whole system and make it less responcible.
4+
This could have led to symptoms including a :exc:`MemoryError`, swapping, out
5+
of memory (OOM) killed processes or containers, or even system crashes.

0 commit comments

Comments
 (0)