Skip to content

Commit a62caed

Browse files
authored
[3.13] Revert "gh-119452: Fix a potential virtual memory allocation denial of service in http.server (GH-119455) (GH-142130)" (#142185)
Revert "[3.13] gh-119452: Fix a potential virtual memory allocation denial of service in http.server (GH-119455) (GH-142130)" This reverts commit 6c922bb.
1 parent 9d99b5b commit a62caed

File tree

3 files changed

+1
-57
lines changed

3 files changed

+1
-57
lines changed

Lib/http/server.py

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,6 @@
127127

128128
DEFAULT_ERROR_CONTENT_TYPE = "text/html;charset=utf-8"
129129

130-
# Data larger than this will be read in chunks, to prevent extreme
131-
# overallocation.
132-
_MIN_READ_BUF_SIZE = 1 << 20
133-
134130
class HTTPServer(socketserver.TCPServer):
135131

136132
allow_reuse_address = 1 # Seems to make sense in testing environment
@@ -1238,16 +1234,7 @@ def run_cgi(self):
12381234
env = env
12391235
)
12401236
if self.command.lower() == "post" and nbytes > 0:
1241-
cursize = 0
1242-
data = self.rfile.read(min(nbytes, _MIN_READ_BUF_SIZE))
1243-
while (len(data) < nbytes and len(data) != cursize and
1244-
select.select([self.rfile._sock], [], [], 0)[0]):
1245-
cursize = len(data)
1246-
# This is a geometric increase in read size (never more
1247-
# than doubling our the current length of data per loop
1248-
# iteration).
1249-
delta = min(cursize, nbytes - cursize)
1250-
data += self.rfile.read(delta)
1237+
data = self.rfile.read(nbytes)
12511238
else:
12521239
data = None
12531240
# throw away additional data [see bug #427345]

Lib/test/test_httpservers.py

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -802,20 +802,6 @@ def test_path_without_leading_slash(self):
802802
print("</pre>")
803803
"""
804804

805-
cgi_file7 = """\
806-
#!%s
807-
import os
808-
import sys
809-
810-
print("Content-type: text/plain")
811-
print()
812-
813-
content_length = int(os.environ["CONTENT_LENGTH"])
814-
body = sys.stdin.buffer.read(content_length)
815-
816-
print(f"{content_length} {len(body)}")
817-
"""
818-
819805

820806
@unittest.skipIf(hasattr(os, 'geteuid') and os.geteuid() == 0,
821807
"This test can't be run reliably as root (issue #13308).")
@@ -855,8 +841,6 @@ def setUp(self):
855841
self.file3_path = None
856842
self.file4_path = None
857843
self.file5_path = None
858-
self.file6_path = None
859-
self.file7_path = None
860844

861845
# The shebang line should be pure ASCII: use symlink if possible.
862846
# See issue #7668.
@@ -911,11 +895,6 @@ def setUp(self):
911895
file6.write(cgi_file6 % self.pythonexe)
912896
os.chmod(self.file6_path, 0o777)
913897

914-
self.file7_path = os.path.join(self.cgi_dir, 'file7.py')
915-
with open(self.file7_path, 'w', encoding='utf-8') as file7:
916-
file7.write(cgi_file7 % self.pythonexe)
917-
os.chmod(self.file7_path, 0o777)
918-
919898
os.chdir(self.parent_dir)
920899

921900
def tearDown(self):
@@ -938,8 +917,6 @@ def tearDown(self):
938917
os.remove(self.file5_path)
939918
if self.file6_path:
940919
os.remove(self.file6_path)
941-
if self.file7_path:
942-
os.remove(self.file7_path)
943920
os.rmdir(self.cgi_child_dir)
944921
os.rmdir(self.cgi_dir)
945922
os.rmdir(self.cgi_dir_in_sub_dir)
@@ -1012,21 +989,6 @@ def test_post(self):
1012989

1013990
self.assertEqual(res.read(), b'1, python, 123456' + self.linesep)
1014991

1015-
def test_large_content_length(self):
1016-
for w in range(15, 25):
1017-
size = 1 << w
1018-
body = b'X' * size
1019-
headers = {'Content-Length' : str(size)}
1020-
res = self.request('/cgi-bin/file7.py', 'POST', body, headers)
1021-
self.assertEqual(res.read(), b'%d %d' % (size, size) + self.linesep)
1022-
1023-
def test_large_content_length_truncated(self):
1024-
for w in range(18, 65):
1025-
size = 1 << w
1026-
headers = {'Content-Length' : str(size)}
1027-
res = self.request('/cgi-bin/file1.py', 'POST', b'x', headers)
1028-
self.assertEqual(res.read(), b'Hello World' + self.linesep)
1029-
1030992
def test_invaliduri(self):
1031993
res = self.request('/cgi-bin/invalid')
1032994
res.read()

Misc/NEWS.d/next/Security/2024-05-23-11-44-41.gh-issue-119452.PRfsSv.rst

Lines changed: 0 additions & 5 deletions
This file was deleted.

0 commit comments

Comments
 (0)