[issue23056] tarfile raises an exception when reading an empty tar in streaming mode

Gregory P. Smith report at bugs.python.org
Mon Dec 15 20:27:54 CET 2014


New submission from Gregory P. Smith:

$ cat >test.py <<EOF
import tarfile
import sys

with tarfile.open(sys.argv[1], mode="r|*") as f:
  while True:
    info = f.next()
    if not info:
      break
EOF
$ tar cf test.tar -T /dev/null
$ python2.7 test.py test.tar
Traceback (most recent call last):
  File "test.py", line 6, in <module>
    info = f.next()
  File "/usr/lib/python2.7/tarfile.py", line 2319, in next
    self.fileobj.seek(self.offset)
  File "/usr/lib/python2.7/tarfile.py", line 555, in seek
    raise StreamError("seeking backwards is not allowed")
tarfile.StreamError: seeking backwards is not allowed
$ python3.4 test.py test.tar
Traceback (most recent call last):
  File "test.py", line 6, in <module>
    info = f.next()
  File "/usr/lib/python3.4/tarfile.py", line 2244, in next
    self.fileobj.seek(self.offset)
  File "/usr/lib/python3.4/tarfile.py", line 518, in seek
    raise StreamError("seeking backwards is not allowed")
tarfile.StreamError: seeking backwards is not allowed

I have reconfirmed that the above still happens using a top of tree 2.7.9+ build.

----------
components: Library (Lib)
messages: 232675
nosy: gregory.p.smith
priority: normal
severity: normal
stage: needs patch
status: open
title: tarfile raises an exception when reading an empty tar in streaming mode
type: behavior
versions: Python 2.7, Python 3.4, Python 3.5

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


More information about the Python-bugs-list mailing list