pathlib.Path.copy() hangs on FIFO pipes and loops infinitely on /dev/zero
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 77.2k
- Forks
- 35.9k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
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
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Empieza en pathlib.Path.copy(), concretamente en _copy_from, y compara su gestión con el comportamiento de shutil.copyfile ante SpecialFileError. Reproduce los casos FIFO y /dev/zero; se considera terminado cuando ambos fallan rápidamente sin bloquearse ni consumir datos sin límite, con cobertura de regresión para este comportamiento.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- operating-systems
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bien especificado
- Aptitud para principiantes
- 25/100