pathlib.Path.copy() can copy a directory into itself via absolute paths or symlinks
未关闭
还没有人认领这个 Issue。
stdlib
type-bug
- 主要语言
- Python
- 星标
- 77.2k
- 派生
- 35.9k
- PR 合并指标
- PR 指标待抓取
描述
Bug report
Bug description:
Bug report
Path.copy() guards against copying a directory into itself with ensure_distinct_paths(), but the check is lexical only. Relative vs absolute paths and symlink aliases bypass it.
from pathlib import Path
import os
Path('src').mkdir()
(Path('src') / 'f').write_text('hello')
Path('src').copy('src/nested') # OSError - OK
Path('src').copy(Path('src').resolve() / 'nested') # succeeds - copies into itself
os.symlink('src', 'link')
Path('src').copy('link/nested') # also succeeds
Same class of bug as gh-149835 that was fixed with `realpath`, but `pathlib` still uses a lexical comparison.
### CPython versions tested on:
CPython main branch
### Operating systems tested on:
Linux
<!-- gh-linked-prs -->
### Linked PRs
* gh-154689
<!-- /gh-linked-prs -->
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 pathlib.Path.copy() 及其 ensure_distinct_paths() 检查入手,然后在 Linux 上复现 issue 中的绝对路径和 symlink 示例。完成的标准是:两个别名都会因试图将目录复制到其自身中而被拒绝,同时现有的相对路径行为仍得到覆盖;查看链接的 PR gh-154689,了解已经在进行的工作。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- python
- 领域
- operating-systems
- Issue 类型
- 缺陷
- 难度
- 3/5
- 预计耗时
- 1-2 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100