[Python-Dev] bug in tarfile module?

Chris Withers chris at simplistix.co.uk
Thu Aug 23 08:46:04 CEST 2012

Hi All,

This feels like a bug, but just wanted to check here before filing a 
report if I've missed something:

buzzkill$ python2.7
Enthought Python Distribution -- www.enthought.com
Version: 7.2-2 (32-bit)

Python 2.7.2 |EPD 7.2-2 (32-bit)| (default, Sep  7 2011, 09:16:50)
[GCC 4.0.1 (Apple Inc. build 5493)] on darwin
Type "packages", "demo" or "enthought" for more information.
 >>> import tarfile
 >>> source = open('/src/Python-2.6.7.tgz', 'rb')
 >>> tar = tarfile.open(fileobj=source, mode='r|*')
 >>> member = tar.extractfile('Python-2.6.7/Lib/genericpath.py')
 >>> data = member.read()
Traceback (most recent call last):
   File "<stdin>", line 1, in <module>
line 815, in read
     buf += self.fileobj.read()
line 735, in read
     return self.readnormal(size)
line 742, in readnormal
     self.fileobj.seek(self.offset + self.position)
line 554, in seek
     raise StreamError("seeking backwards is not allowed")
tarfile.StreamError: seeking backwards is not allowed

The key is the "mode='r*|" which I understood to be specifically for 
reading blocks from a stream without seeking that would cause problems.

I've reproduced on Py26 and Py27 on Mac OS X, and Py26 on SUSE.



Simplistix - Content Management, Batch Processing & Python Consulting
             - http://www.simplistix.co.uk

More information about the Python-Dev mailing list