Skip to content

Commit 5be338e

Browse files
authored
Merge branch '3.13' into backport-c39ae89-3.13
2 parents fe53458 + 87d587f commit 5be338e

File tree

4 files changed

+33
-5
lines changed

4 files changed

+33
-5
lines changed

.github/workflows/jit.yml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,15 @@ jobs:
117117
- name: Native Windows
118118
if: runner.os == 'Windows' && matrix.architecture != 'ARM64'
119119
run: |
120-
choco upgrade llvm -y
121-
choco install llvm --allow-downgrade --no-progress --version ${{ matrix.llvm }}
120+
choco install llvm --allow-downgrade --no-progress --version ${{ matrix.llvm }}.1.0
122121
./PCbuild/build.bat --experimental-jit ${{ matrix.debug && '-d' || '--pgo' }} -p ${{ matrix.architecture }}
123122
./PCbuild/rt.bat ${{ matrix.debug && '-d' || '' }} -p ${{ matrix.architecture }} -q --multiprocess 0 --timeout 4500 --verbose2 --verbose3
124123
125124
# No PGO or tests (yet):
126125
- name: Emulated Windows
127126
if: runner.os == 'Windows' && matrix.architecture == 'ARM64'
128127
run: |
129-
choco upgrade llvm -y
130-
choco install llvm --allow-downgrade --no-progress --version ${{ matrix.llvm }}
128+
choco install llvm --allow-downgrade --no-progress --version ${{ matrix.llvm }}.1.0
131129
./PCbuild/build.bat --experimental-jit ${{ matrix.debug && '-d' || '' }} -p ${{ matrix.architecture }}
132130
133131
- name: Native macOS

Lib/imaplib.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@
5252
# search command can be quite large, so we now use 1M.
5353
_MAXLINE = 1000000
5454

55+
# Data larger than this will be read in chunks, to prevent extreme
56+
# overallocation.
57+
_SAFE_BUF_SIZE = 1 << 20
5558

5659
# Commands
5760

@@ -315,7 +318,13 @@ def open(self, host='', port=IMAP4_PORT, timeout=None):
315318

316319
def read(self, size):
317320
"""Read 'size' bytes from remote."""
318-
return self.file.read(size)
321+
cursize = min(size, _SAFE_BUF_SIZE)
322+
data = self.file.read(cursize)
323+
while cursize < size and len(data) == cursize:
324+
delta = min(cursize, size - cursize)
325+
data += self.file.read(delta)
326+
cursize += delta
327+
return data
319328

320329

321330
def readline(self):

Lib/test/test_imaplib.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,20 @@ def handle(self):
901901
self.assertRaises(imaplib.IMAP4.error,
902902
self.imap_class, *server.server_address)
903903

904+
def test_truncated_large_literal(self):
905+
size = 0
906+
class BadHandler(SimpleIMAPHandler):
907+
def handle(self):
908+
self._send_textline('* OK {%d}' % size)
909+
self._send_textline('IMAP4rev1')
910+
911+
for exponent in range(15, 64):
912+
size = 1 << exponent
913+
with self.subTest(f"size=2e{size}"):
914+
with self.reaped_server(BadHandler) as server:
915+
with self.assertRaises(imaplib.IMAP4.abort):
916+
self.imap_class(*server.server_address)
917+
904918
@threading_helper.reap_threads
905919
def test_simple_with_statement(self):
906920
# simplest call
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Fix a potential denial of service in the :mod:`imaplib` module. When connecting
2+
to a malicious server, it could cause an arbitrary amount of memory to be
3+
allocated. On many systems this is harmless as unused virtual memory is only a
4+
mapping, but if this hit a virtual address size limit it could lead to a
5+
:exc:`MemoryError` or other process crash. On unusual systems or builds where
6+
all allocated memory is touched and backed by actual ram or storage it could've
7+
consumed resources doing so until similarly crashing.

0 commit comments

Comments
 (0)