This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: TarFile.getmembers fails at struct.unpack: unpack requires a string argument of length 4
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.4
process
Status: closed Resolution: out of date
Dependencies: 6584 Superseder:
Assigned To: Nosy List: ezio.melotti, maker, mikecmcleod, r.david.murray, serhiy.storchaka, srid, vstinner
Priority: normal Keywords: easy

Created on 2009-08-07 21:11 by srid, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (7)
msg91412 - (view) Author: Sridhar Ratnakumar (srid) Date: 2009-08-07 21:11
Perhaps this must be wrapped under a programmer-expected custom 
exception class (TarError maybe)

    for tarinfo in tarfileobj.getmembers():
  File "/home/apy/ActivePython-2.6/lib/python2.6/tarfile.py", line 
1791, in getmembers
    self._load()        # all members, we first have to
  File "/home/apy/ActivePython-2.6/lib/python2.6/tarfile.py", line 
2352, in _load
    tarinfo = self.next()
  File "/home/apy/ActivePython-2.6/lib/python2.6/tarfile.py", line 
2307, in next
    self.fileobj.seek(self.offset)
  File "/home/apy/ActivePython-2.6/lib/python2.6/gzip.py", line 382, in 
seek
    self.read(1024)
  File "/home/apy/ActivePython-2.6/lib/python2.6/gzip.py", line 219, in 
read
    self._read(readsize)
  File "/home/apy/ActivePython-2.6/lib/python2.6/gzip.py", line 267, in 
_read
    self._read_eof()
  File "/home/apy/ActivePython-2.6/lib/python2.6/gzip.py", line 300, in 
_read_eof
    crc32 = read32(self.fileobj)
  File "/home/apy/ActivePython-2.6/lib/python2.6/gzip.py", line 24, in 
read32
    return struct.unpack("<I", input.read(4))[0]
error: unpack requires a string argument of length 4
msg91577 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2009-08-14 22:51
First, gzip should use its own errors: this issue depends on #6584.
msg91578 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2009-08-14 22:59
Since 6584 is deemed (correctly, IMO) a feature request, this one must
be as well.
msg142521 - (view) Author: Michele Orrù (maker) * Date: 2011-08-20 10:37
Would it be better to use TarError as Sridhar suggested, or create a new class BadTarfile(TarError, IOError), following the convention used for gzip and zipfile?
msg176848 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-12-03 16:02
See also related issue4844 and issue14315 for zipfile.
msg406200 - (view) Author: mike mcleod (mikecmcleod) * Date: 2021-11-12 10:17
I would like to help with this issue.
I note that when I test against 3.10 this error does not show. Also, all tests for test_tarfile pass.
I am wondering if it may be reasonable to close this due to the age and currently its not an issue in the latest Python version.
msg406593 - (view) Author: STINNER Victor (vstinner) * (Python committer) Date: 2021-11-19 16:41
File "/home/apy/ActivePython-2.6/lib/python2.6/gzip.py", line 24, in 
read32
    return struct.unpack("<I", input.read(4))[0]
error: unpack requires a string argument of length 4

The gzip.read32() function has been removed in Python 3:

commit 7c3922f44c226eac29a497648bbc3cc8702905a8
Author: Serhiy Storchaka <storchaka@gmail.com>
Date:   Tue Jan 22 17:01:59 2013 +0200

    Issue #1159051: GzipFile now raises EOFError when reading a corrupted file
    with truncated header or footer.
    Added tests for reading truncated gzip and bzip2 files.

---


  File "/home/apy/ActivePython-2.6/lib/python2.6/tarfile.py", line 
2307, in next
    self.fileobj.seek(self.offset)
  File "/home/apy/ActivePython-2.6/lib/python2.6/gzip.py", line 382, in 
seek
    self.read(1024)

Moreover, gzip.GzipFile().seek() no longer calls self.read(1024):

commit 2dbc6e6bce0a29757acddd8000d55f7c844295a2
Author: Antoine Pitrou <solipsis@pitrou.net>
Date:   Sat Apr 11 00:31:01 2015 +0200

    Issue #23529: Limit the size of decompressed data when reading from
    GzipFile, BZ2File or LZMAFile.  This defeats denial of service attacks
    using compressed bombs (i.e. compressed payloads which decompress to a huge
    size).
    
    Patch by Martin Panter and Nikolaus Rath.

IMO it's no longer possible to reproduce the gzip.error on gzip.GzipFile.seek(), so I close the issue as out of date.
History
Date User Action Args
2022-04-11 14:56:51adminsetgithub: 50918
2021-11-19 16:41:42vstinnersetstatus: open -> closed
resolution: out of date
messages: + msg406593

stage: test needed -> resolved
2021-11-12 10:17:27mikecmcleodsetnosy: + mikecmcleod
messages: + msg406200
2012-12-03 16:02:44serhiy.storchakasetnosy: + serhiy.storchaka

messages: + msg176848
versions: + Python 3.4, - Python 3.3
2011-08-24 07:13:11makersetnosy: + ezio.melotti
2011-08-20 10:37:00makersetnosy: + maker
messages: + msg142521
2011-07-22 19:40:04terry.reedysetversions: + Python 3.3, - Python 2.7, Python 3.2
2009-08-14 22:59:40r.david.murraysetpriority: normal

dependencies: + gzip module has no custom exception
type: behavior -> enhancement
versions: + Python 2.7, Python 3.2, - Python 2.6
keywords: + easy
nosy: + r.david.murray

messages: + msg91578
stage: test needed
2009-08-14 22:51:56vstinnersetnosy: + vstinner
messages: + msg91577
2009-08-07 21:11:15sridcreate