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
派生
35.9k
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 摘要。