[New-bugs-announce] [issue2846] Gzip cannot handle zero-padded output + patch

Tadek Pietraszek report at bugs.python.org
Wed May 14 00:16:23 CEST 2008

New submission from Tadek Pietraszek <tadek at pietraszek.org>:

There are cases when gzip produces/receives a zero-padded output, for
example when creating a compressed tar archive with a pipe:

tar cz /dev/null > foo.tgz

ls -la foo.tgz
-rw-r----- 1 tadek tadek 10240 May 13 23:40 foo.tgz

tar tvfz foo.tgz
crw-rw-rw- root/root       1,3 2007-10-18 18:27:25 dev/null

This is a known behavior (http://www.gzip.org/#faq8) and recent versions
of gzip handle it gracefully by skipping all zero bytes after the end of
the file (see gzip.c:1394-1406 in the version 1.3.12).

The Python gzip module crashes on those files:

#:~/python2.5/py2.5$ tar cz /dev/null > foo.tgz
tar: Removing leading `/' from member names
#:~/python2.5/py2.5$ bin/python
Python 2.5.2 (r252:60911, May 14 2008, 00:02:24)
[GCC 4.0.3 (Ubuntu 4.0.3-1ubuntu5)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import gzip
>>> f=gzip.open("foo.tgz")
>>> f.read()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/tadek/python2.5/py2.5/lib/python2.5/gzip.py", line 220, in
  File "/home/tadek/python2.5/py2.5/lib/python2.5/gzip.py", line 263, in
  File "/home/tadek/python2.5/py2.5/lib/python2.5/gzip.py", line 164, in
    raise IOError, 'Not a gzipped file'
IOError: Not a gzipped file

The proposed patch fixes this behavior by reading all zero characters at
the end of the file. I tested that it works with: regular archives,
zero-padded archives, concatenated archives and concatenated zero-padded


components: Extension Modules
files: python2.5.2-gzip.patch
keywords: patch
messages: 66806
nosy: tadek
severity: normal
status: open
title: Gzip cannot handle zero-padded output + patch
type: behavior
versions: Python 2.5
Added file: http://bugs.python.org/file10320/python2.5.2-gzip.patch

Tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list