python / python/cpython

Tarfile extraction does not work on Windows

未关闭
#95,763 6 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

3.10 3.11 3.12 OS-windows stdlib triaged type-bug
主要语言
Python
星标
77.2k
派生
36k
PR 合并指标
PR 指标待抓取

描述

Using Python 3.10.5, there is a scenario where the extractall function of tarfile is causing an infinite loop for Python on Windows, but not in Linux.

The tar-file where the issue occurred was the one produced by docker export, where a file-system is saved as a tar file. Unfortunately, it is too big to upload here, so I will give some commands to get this file.

> docker create --name "testcontainer" tomcat
> docker export --output="testtomcat.tar" testcontainer

That should produce a file of about 457MB.

Now, using Python 3.10.5 under Windows, the following code-snippet will crash:

import tarfile
with tarfile.open("testtomcat.tar") as tarf:
     members_to_extract = [tar_info for tar_info in tarf.getmembers()
                                           if not tar_info.isdev()]
     tarf.extractall(path="/tmp/foo/", members=members_to_extract)

The error says: maximum recursion depth exceeded while calling a Python object

Your environment

  • CPython versions tested on: Python 3.10.5
  • Operating system and architecture: Windows 11 is where it failed, and it works fine with the same python version in Arch Linux with kernel Linux 5.15.58-2-lts x86_64

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 tarfile.extractall 和报告中展示的 members 过滤开始,然后使用 docker create 和 docker export 命令在 Windows 上重现该行为。将其与在 Linux 上使用相同 Python 版本进行的解压结果进行比较。当导出的 tar 存档能够在 Windows 上解压,且不会出现递归深度失败或无限循环时,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
docker, python
领域
operating-systems
Issue 类型
缺陷
难度
4/5
预计耗时
3-5 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
35/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。