Skip to content

Commit e6c3e7b

Browse files
Address review comments.
1 parent 9f06e71 commit e6c3e7b

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

Lib/http/server.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@
136136

137137
# Data larger than this will be read in chunks, to prevent extreme
138138
# overallocation.
139-
SAFE_BUF_SIZE = 1 << 20
139+
_MIN_READ_BUF_SIZE = 1 << 20
140140

141141
class HTTPServer(socketserver.TCPServer):
142142

@@ -1289,10 +1289,13 @@ def run_cgi(self):
12891289
)
12901290
if self.command.lower() == "post" and nbytes > 0:
12911291
cursize = 0
1292-
data = self.rfile.read(min(nbytes, SAFE_BUF_SIZE))
1292+
data = self.rfile.read(min(nbytes, _MIN_READ_BUF_SIZE))
12931293
while (len(data) < nbytes and len(data) != cursize and
12941294
select.select([self.rfile._sock], [], [], 0)[0]):
12951295
cursize = len(data)
1296+
# This is a geometric increase in read size (never more
1297+
# than doubling our the current length of data per loop
1298+
# iteration).
12961299
delta = min(cursize, nbytes - cursize)
12971300
data += self.rfile.read(delta)
12981301
else:
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.server` module.
1+
Fix a potential memory denial of service in the :mod:`http.server` module.
22
When a malicious user is connected to the CGI server on Windows, 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)