pathlib.Path.copy() hangs on FIFO pipes and loops infinitely on /dev/zero
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
Bug Description
pathlib.Path.copy() (introduced recently) attempts to open and copy any file type that is not a directory or a symlink. This causes severe issues with special files:
- FIFOs (Named Pipes): Opening a FIFO for reading blocks indefinitely if there is no writer, causing the process to hang using CPU.
- Infinite Sources: Reading from character devices like
/dev/zeroresults in an infinite loop, potentially filling up the disk or freezing the application.
shutil.copyfile correctly handles this by raising SpecialFileError (or similar) when encountering these files. pathlib should behave similarly or at least safely.
Reproduction
import os
import pathlib
import signal
import time
fifo_name = "test_fifo_hang"
if os.path.exists(fifo_name):
os.remove(fifo_name)
os.mkfifo(fifo_name)
# This will hang indefinitely
print("Attempting to copy FIFO...")
p = pathlib.Path(fifo_name)
try:
p.copy("test_fifo_dest")
except Exception as e:
print(f"Caught: {e}")
else:
print("Copy finished (unexpected!)")
finally:
os.remove(fifo_name)
Expected Behavior
The operation should fail immediately with io.UnsupportedOperation or shutil.SameFileError / SpecialFileError instead of hanging or looping.
Proposed Solution
Check is_file() in pathlib.Path.copy (specifically _copy_from) to ensure we only copy regular files.
I have a PR ready for this.
CPython versions tested on:
3.14
Operating systems tested on:
macOS
Linked PRs
- gh-143966
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
pathlib.Path.copy()、具体的には _copy_from から始め、その処理を shutil.copyfile の SpecialFileError に対する動作と比較します。FIFO と /dev/zero のケースを再現します。両方がブロックしたり無制限のデータを消費したりせず、速やかに失敗し、この動作に対する回帰テストのカバレッジがあることを完了条件とします。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- operating-systems
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 25/100