From c316416b972d1b05e58fbcc21e80428b900ce102 Mon Sep 17 00:00:00 2001 From: Simon Sawicki Date: Wed, 2 Jul 2025 01:42:00 +0200 Subject: [PATCH] [rh:requests] Do not allocate 2GB on read (#13603) Fixes c2ff2dbaec7929015373fe002e9bd4849931a4ce Authored by: Grub4K --- yt_dlp/networking/_requests.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/yt_dlp/networking/_requests.py b/yt_dlp/networking/_requests.py index 2927ea7ffb..555c21ac33 100644 --- a/yt_dlp/networking/_requests.py +++ b/yt_dlp/networking/_requests.py @@ -143,7 +143,9 @@ class RequestsResponseAdapter(Response): # Work around issue with `.read(amt)` then `.read()` # See: https://github.com/urllib3/urllib3/issues/3636 if amt is None: - amt = (1 << 31) - 1 + # Python 3.9 preallocates the whole read buffer, read in chunks + read_chunk = functools.partial(self.fp.read, 1 << 20, decode_content=True) + return b''.join(iter(read_chunk, b'')) # Interact with urllib3 response directly. return self.fp.read(amt, decode_content=True)