python / python/cpython

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

オープン
#153,460 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

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. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

zipfile.ZipFile のエントリーポイントから始め、多数のエントリーを含む ZIP に対して報告された tracemalloc の再現コードを実行してください。作業がすでに進行中である可能性があるため、開始前にリンク先の PR gh-153465 を確認してください。初期化によって内部の ZipInfo エントリーキャッシュがメモリを使い果たさなくなり、報告された多数エントリーのケースがテストでカバーされれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
backend
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
20/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。