python / python/cpython

Tarfile extraction does not work on Windows

Open
#95,763 6 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

3.10 3.11 3.12 OS-windows stdlib triaged type-bug
Dominant language
Python
Stars
77.2k
Forks
36k
PR merge metrics
PR metrics pending

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with tarfile.extractall and the members filtering shown in the report, then reproduce the behavior on Windows using the docker create and docker export commands. Compare extraction with the same Python version on Linux. Done means the exported tar archive can be extracted on Windows without the recursion-depth failure or infinite loop.

Written by the indexing model from the issue text.

Assessment

Tech stack
docker, python
Domain
operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.