From f650dfa622df2a3589aced764358d8eafe23957c Mon Sep 17 00:00:00 2001 From: Forest Date: Tue, 4 Feb 2025 14:11:32 -0800 Subject: [PATCH] imaplib: comment on benefit of reading in chunks Our read() implementation designed to support IDLE replaces the one from PR #119514, fixing the same problem it was addressing. The tests that it added are preserved. --- Lib/imaplib.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Lib/imaplib.py b/Lib/imaplib.py index 0203feb133bc11..7dc076244a34ed 100644 --- a/Lib/imaplib.py +++ b/Lib/imaplib.py @@ -344,6 +344,12 @@ def read(self, size): # error condition instead of letting the caller decide how to handle a # timeout. We therefore implement our own buffered read(). # https://github.com/python/cpython/issues/51571 + # + # Reading in chunks instead of delegating to a single + # BufferedReader.read() call also means we avoid its preallocation + # of an unreasonably large memory block if a malicious server claims + # it will send a huge literal without actually sending one. + # https://github.com/python/cpython/issues/119511 parts = []