Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/tarfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,8 +372,8 @@ def __init__(self, name, mode, comptype, fileobj, bufsize,
self.zlib = zlib
self.crc = zlib.crc32(b"")
if mode == "r":
self._init_read_gz()
self.exception = zlib.error
self._init_read_gz()
else:
self._init_write_gz(compresslevel)

Expand Down
17 changes: 17 additions & 0 deletions Lib/test/test_tarfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -938,6 +938,23 @@ class LzmaDetectReadTest(LzmaTest, DetectReadTest):
pass


class GzipBrokenHeaderCorrectException(GzipTest, unittest.TestCase):
"""
See: https://github.com/python/cpython/issues/107396
"""
def runTest(self):
f = io.BytesIO(
b'\x1f\x8b' # header
b'\x08' # compression method
b'\x04' # flags
b'\0\0\0\0\0\0' # padding?
Comment thread
encukou marked this conversation as resolved.
Outdated
b'\0\x01' # size
b'\0\0\0\0\0' # corrupt data (zeros)
)
with self.assertRaises(tarfile.ReadError):
tarfile.open(fileobj=f, mode='r|gz')


class MemberReadTest(ReadTest, unittest.TestCase):

def _test_member(self, tarinfo, chksum=None, **kwargs):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
tarfiles; Fixed use before assignment of self.exception for gzip decompression