Issue 6669: TarFile.getmembers fails at struct.unpack: unpack requires a string argument of length 4 (original) (raw)
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)
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
Author: STINNER Victor (vstinner) *
Date: 2009-08-14 22:51
First, gzip should use its own errors: this issue depends on #6584.
Author: R. David Murray (r.david.murray) *
Date: 2009-08-14 22:59
Since 6584 is deemed (correctly, IMO) a feature request, this one must be as well.
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?
Author: Serhiy Storchaka (serhiy.storchaka) *
Date: 2012-12-03 16:02
See also related and for zipfile.
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.
Author: STINNER Victor (vstinner) *
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](issue1159051 "[open] Handle corrupted gzip files with unexpected EOF"): 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](issue23529 "[closed] Limit decompressed data when reading from LZMAFile and BZ2File"): 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:51
admin
set
github: 50918
2021-11-19 16:41:42
vstinner
set
status: open -> closed
resolution: out of date
messages: +
stage: test needed -> resolved
2021-11-12 10:17:27
mikecmcleod
set
nosy: + mikecmcleod
messages: +
2012-12-03 16:02:44
serhiy.storchaka
set
nosy: + serhiy.storchaka
messages: +
versions: + Python 3.4, - Python 3.3
2011-08-24 07:13:11
maker
set
nosy: + ezio.melotti
2011-08-20 10:37:00
maker
set
nosy: + maker
messages: +
2011-07-22 19:40:04
terry.reedy
set
versions: + Python 3.3, - Python 2.7, Python 3.2
2009-08-14 22:59:40
r.david.murray
set
priority: 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: +
stage: test needed
2009-08-14 22:51:56
vstinner
set
nosy: + vstinner
messages: +
2009-08-07 21:11:15
srid
create