python / python/cpython

zipfiles.ZipFile's internal ZipInfo entry cache has no internal bounds

未關閉
#153,460 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

還沒有人認領這個 Issue。

stdlib type-bug
主要語言
Python
星號
77.2k
分支
36k
PR 合併指標
PR 指標待擷取

描述

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
  • gh-153465

貢獻指南

開啟貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

研究方向

從 zipfile.ZipFile 進入點開始,針對包含大量項目的 ZIP 執行報告中的 tracemalloc 重現程式。開始前請檢視連結的 PR gh-153465,因為相關工作可能已經在進行中。完成的標準是:初始化不再允許內部 ZipInfo 項目快取耗盡記憶體,並且為報告中的大量項目案例加入測試涵蓋。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
backend
Issue 類型
缺陷
難度
4/5
預估耗時
3-5 天
活躍度
停滯
描述清晰度
基本清楚
新手友好度
20/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。