[issue21044] tarfile does not handle file .name being an int

Martin Panter report at bugs.python.org
Tue Apr 22 06:34:31 CEST 2014


Martin Panter added the comment:

I ran into a related issue with the gettarinfo() method. Would that fall under the scope of this bug, or should I raise a separate one?

>>> with tarfile.open("/dev/null", "w") as tar:
...     with open(b"/bin/sh", "rb") as file:
...         tar.gettarinfo(fileobj=file)
... 
Traceback (most recent call last):
  File "<stdin>", line 3, in <module>
  File "/usr/lib/python3.4/tarfile.py", line 1768, in gettarinfo
    arcname = arcname.replace(os.sep, "/")
TypeError: expected bytes, bytearray or buffer compatible object

I realise that making TarInfo object with a byte string or integer as a file name is not a good idea. Perhaps the documentation should explicitly say that “fileobj.name” must be a real unencoded file name string unless “arcname” is also given. In my particular case I added arcname="", because my code generates the proper file name later on.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21044>
_______________________________________


More information about the Python-bugs-list mailing list