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

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
gh-107396: tarfiles: set self.exception before _init_read_gz()
In the stack call of: _init_read_gz()
```
_read, tarfile.py:548
read, tarfile.py:526
_init_read_gz, tarfile.py:491
```
a try;except exists that uses `self.exception`, so it needs to be set before
calling _init_read_gz().

closes: #107396
  • Loading branch information
balmeida-nokia committed Aug 18, 2023
commit e834e786a5997f5f4bfdf4686bbd560133d88faa
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