Title: tarfile: unexpected IsADirectoryError on extraction
Type: behavior Stage:
Components: Versions: Python 3.8, Python 3.7, Python 3.6
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: alter-bug-tracer
Priority: normal Keywords:

Created on 2019-05-21 07:13 by alter-bug-tracer, last changed 2019-06-02 22:04 by mangrisano.

File name Uploaded Description Edit
input0.tar alter-bug-tracer, 2019-05-21 07:13
Messages (2)
msg342983 - (view) Author: alter-bug-tracer (alter-bug-tracer) * Date: 2019-05-21 07:13
The following code creates a new directory 'output' and extracts the tar archive given as argv in it. When a malformed archive (attached) is given as argv, a IsADirectoryError is thrown, as opposed to extracting the file contained in the archive to the 'output' directory.

import tarfile
import sys
import os

def extract(archive_path, destination_path):
  if not tarfile.is_tarfile(archive_path):
    print ('Not a tar file')
  tar =, 'r')
  for info in tar.getmembers():
    tar.extractall(destination_path, members=[tar.getmember(])

destination_path = 'output'
extract(sys.argv[1], destination_path)

Traceback (most recent call last):
  File "", line 15, in <module>
    extract(sys.argv[1], destination_path)
  File "", line 11, in extract
    tar.extractall(destination_path, members=[tar.getmember(])
  File "/usr/lib/python3.6/", line 2010, in extractall
  File "/usr/lib/python3.6/", line 2052, in extract
  File "/usr/lib/python3.6/", line 2122, in _extract_member
    self.makefile(tarinfo, targetpath)
  File "/usr/lib/python3.6/", line 2163, in makefile
    with bltn_open(targetpath, "wb") as target:
IsADirectoryError: [Errno 21] Is a directory: 'output'
msg343005 - (view) Author: Michele Angrisano (mangrisano) * Date: 2019-05-21 10:47
It looks like it has the same behavior of issue8958.
Date User Action Args
2019-06-02 22:04:23mangrisanosetnosy: - mangrisano
2019-05-21 10:47:21mangrisanosetnosy: + mangrisano
messages: + msg343005
2019-05-21 07:13:29alter-bug-tracercreate