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: gzip module has no custom exception
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.8
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: ZackerySpytz, dstanek, eric.araujo, ezio.melotti, gruszczy, maker, pitrou, serhiy.storchaka, srid, terry.reedy
Priority: normal Keywords: patch

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

Files
File name Uploaded Description Edit
6584_1.patch gruszczy, 2010-03-16 20:21 review
6584_2.patch gruszczy, 2010-03-16 20:47 review
6584_3.patch gruszczy, 2011-03-15 10:08 review
6584_4.patch maker, 2011-08-20 08:15 review
6584_5.patch maker, 2011-08-20 09:03 review
issue6584_6.patch maker, 2012-11-10 16:07 review
Pull Requests
URL Status Linked Edit
PR 13022 merged ZackerySpytz, 2019-04-30 10:36
Messages (20)
msg90976 - (view) Author: Sridhar Ratnakumar (srid) Date: 2009-07-27 06:10
Much like zipfile.BadZipfile, we need a base custom exception for the 
gzip module. At least, catch gzip-related exceptions and throw a 
tarfile.TarError when used *via* tarfile.*.

See the following example (the exception escaped the "try... except 
tarfile.TarError: .. " block!):

***
  [...]
  File "/home/sridharr/as/pypm/src/pypm/common/compression.py", line 
199, in _ensure_read_write_access
    for tarinfo in tarfileobj.getmembers():
  File "/opt/ActivePython-2.6/lib/python2.6/tarfile.py", line 1791, in 
getmembers
    self._load()        # all members, we first have to
  File "/opt/ActivePython-2.6/lib/python2.6/tarfile.py", line 2352, in 
_load
    tarinfo = self.next()
  File "/opt/ActivePython-2.6/lib/python2.6/tarfile.py", line 2307, in 
next
    self.fileobj.seek(self.offset)
  File "/opt/ActivePython-2.6/lib/python2.6/gzip.py", line 382, in seek
    self.read(1024)
  File "/opt/ActivePython-2.6/lib/python2.6/gzip.py", line 219, in read
    self._read(readsize)
  File "/opt/ActivePython-2.6/lib/python2.6/gzip.py", line 284, in _read
    self._read_eof()
  File "/opt/ActivePython-2.6/lib/python2.6/gzip.py", line 304, in 
_read_eof
    hex(self.crc)))
IOError: CRC check failed 0x115929f0 != 0x9f074a38L
msg91151 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2009-07-31 20:32
Unless something in the docs claims that there is/should be such a
thing, this is a feature request, not a bug ('behavior') report, and
only applicable to future x.y versions.
msg101185 - (view) Author: Filip Gruszczyński (gruszczy) Date: 2010-03-16 20:21
I have created a small patch, that introduces BadGzipFile exception. It is a subclass of IOError, so it would be backward compatible and will be still caught by old code, but this way is distinct from IOError.
msg101187 - (view) Author: Filip Gruszczyński (gruszczy) Date: 2010-03-16 20:47
Modified patch with test, that catches both BadGzipFile and IOError exceptions.
msg130842 - (view) Author: Filip Gruszczyński (gruszczy) Date: 2011-03-14 16:09
Bump! How about commiting this patch? Or maybe there is something missing? I'll be happy to fix it.
msg130844 - (view) Author: Antoine Pitrou (pitrou) * (Python committer) Date: 2011-03-14 16:15
Since the patch makes BadGzipFile a subclass of IOError, it doesn't look unreasonable.
Some nits:
- a gzipped file is not an "archive"
- the unit tests should use either the "with" statement, or try/finally blocks to properly close the file even when the test fails
- you should probably explicitly test that BadGzipFile is a subclass of IOError
msg130883 - (view) Author: Filip Gruszczyński (gruszczy) Date: 2011-03-14 19:56
I'll be very happy to fix this after Friday. Thanks for your comments.
msg130961 - (view) Author: Filip Gruszczyński (gruszczy) Date: 2011-03-15 10:08
I had some time today, so I managed to fix the patch. I hope now everything is ok.
msg138536 - (view) Author: Filip Gruszczyński (gruszczy) Date: 2011-06-17 17:50
Bump! Antoine, do you think the patch is acceptable and can be committed now?
msg138544 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2011-06-17 18:46
Your changes appear to address all three of Antoine's 'nits'.
msg138732 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2011-06-20 15:32
Ezio has found a few other things to improve (follow the “review” link to the right of the patch link).
msg142517 - (view) Author: Michele Orrù (maker) * Date: 2011-08-20 08:15
The attached patch follows Ezio's hints.
msg174685 - (view) Author: Ezio Melotti (ezio.melotti) * (Python committer) Date: 2012-11-03 20:16
The new exception should also be documented, and a versionadded and Doc/whatsnew/3.4.rst entry added.
msg175285 - (view) Author: Michele Orrù (maker) * Date: 2012-11-10 16:07
done!
msg175286 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-11-10 16:27
Not all invalid gzip files raise BadGzipFile.  Some of them raises ZlibError.
msg175289 - (view) Author: Michele Orrù (maker) * Date: 2012-11-10 16:57
Well, I specified the word ``files`` everywhere for that reason. Looking at Doc/library/zlib.rst I see:

  For reading and writing .gz files see the gzip module.

Also, I specified 'the gzip module' on the whatsnew section.
Is there anything more specific I could have done?
msg176385 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-11-25 19:02
I added some comments on Rietveld.
msg176891 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2012-12-04 10:32
read32() should raise BadGzipFile when less than 4 bytes read. Also you should introduce read8() function which raises BadGzipFile when less than 1 byte read.

See also issue4844 and issue14315 for zipfile.
msg341145 - (view) Author: Zackery Spytz (ZackerySpytz) * (Python triager) Date: 2019-04-30 10:37
I'd like to see this issue move forward, so I've created a PR.
msg342288 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2019-05-13 07:51
New changeset cf599f6f6f1c392d8f12936982a370d533782195 by Serhiy Storchaka (Zackery Spytz) in branch 'master':
bpo-6584: Add a BadGzipFile exception to the gzip module. (GH-13022)
https://github.com/python/cpython/commit/cf599f6f6f1c392d8f12936982a370d533782195
History
Date User Action Args
2022-04-11 14:56:51adminsetgithub: 50833
2019-05-13 07:53:07serhiy.storchakasetstatus: open -> closed
resolution: fixed
stage: patch review -> resolved
2019-05-13 07:51:01serhiy.storchakasetmessages: + msg342288
2019-04-30 10:37:44ZackerySpytzsetnosy: + ZackerySpytz

messages: + msg341145
versions: + Python 3.8, - Python 3.4
2019-04-30 10:36:58ZackerySpytzsetstage: needs patch -> patch review
pull_requests: + pull_request12944
2012-12-04 10:32:23serhiy.storchakasetmessages: + msg176891
stage: commit review -> needs patch
2012-11-25 19:02:03serhiy.storchakasetmessages: + msg176385
2012-11-10 16:57:30makersetmessages: + msg175289
2012-11-10 16:27:42serhiy.storchakasetnosy: + serhiy.storchaka
messages: + msg175286
2012-11-10 16:07:53makersetfiles: + issue6584_6.patch

messages: + msg175285
2012-11-03 20:16:49ezio.melottisetmessages: + msg174685
versions: + Python 3.4, - Python 3.3
2011-08-24 07:12:45makersetnosy: + ezio.melotti
2011-08-20 09:03:31makersetfiles: + 6584_5.patch
2011-08-20 08:15:42makersetfiles: + 6584_4.patch
nosy: + maker
messages: + msg142517

2011-06-20 15:32:32eric.araujosetnosy: + eric.araujo
messages: + msg138732
2011-06-17 18:46:19terry.reedysetmessages: + msg138544
stage: patch review -> commit review
2011-06-17 17:50:24gruszczysetmessages: + msg138536
2011-03-15 10:08:35gruszczysetfiles: + 6584_3.patch
nosy: terry.reedy, pitrou, dstanek, gruszczy, srid
messages: + msg130961
2011-03-14 19:56:15gruszczysetnosy: terry.reedy, pitrou, dstanek, gruszczy, srid
messages: + msg130883
2011-03-14 16:15:33pitrousetnosy: + pitrou
messages: + msg130844
2011-03-14 16:09:23gruszczysetnosy: terry.reedy, dstanek, gruszczy, srid
messages: + msg130842
2011-01-26 23:51:20pitrousetnosy: terry.reedy, dstanek, gruszczy, srid
stage: needs patch -> patch review
versions: + Python 3.3, - Python 2.7, Python 3.2
2011-01-26 17:51:51dstaneksetnosy: + dstanek
2010-03-16 20:47:36gruszczysetfiles: + 6584_2.patch

messages: + msg101187
2010-03-16 20:21:34gruszczysetfiles: + 6584_1.patch

nosy: + gruszczy
messages: + msg101185

keywords: + patch
2009-08-14 22:59:39r.david.murraylinkissue6669 dependencies
2009-07-31 20:32:12terry.reedysetversions: + Python 2.7, - Python 2.6, Python 3.1
nosy: + terry.reedy

messages: + msg91151

type: behavior -> enhancement
2009-07-27 06:17:18amaury.forgeotdarcsetstage: needs patch
2009-07-27 06:13:17sridsetversions: + Python 3.1, Python 3.2
2009-07-27 06:10:48sridcreate