Bug report
Bug description:
ZIP files with substantially many entries will exhaust memory when initialized using the zipfile module. As far as I know, there is no way to prevent this using the zipfile.ZipFile API.
The following code produces a ZIP file of 427 MB:
import zipfile
import tracemalloc
N = 5_000_000
tracemalloc.start()
try:
with zipfile.ZipFile("test.zip", "w") as zf:
for i in range(N):
zf.writestr(str(i), "")
finally:
m, _ = tracemalloc.get_traced_memory()
print(f"{m >> 20} MB")
The following code on the produced ZIP file outputs 2408 MB on my machine:
import zipfile
import tracemalloc
tracemalloc.start()
try:
with zipfile.ZipFile("test.zip", "r") as zf:
pass
finally:
m, _ = tracemalloc.get_traced_memory()
print(f"{m >> 20} MB")
CPython versions tested on:
CPython main branch, 3.14
Operating systems tested on:
Linux
Linked PRs
Bug report
Bug description:
ZIP files with substantially many entries will exhaust memory when initialized using the
zipfilemodule. As far as I know, there is no way to prevent this using thezipfile.ZipFileAPI.The following code produces a ZIP file of 427 MB:
The following code on the produced ZIP file outputs
2408 MBon my machine:CPython versions tested on:
CPython main branch, 3.14
Operating systems tested on:
Linux
Linked PRs