mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
gh-107396: tarfiles: set self.exception before _init_read_gz() (GH-107485)
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().
This commit is contained in:
parent
80bdebdd85
commit
37135d25e2
3 changed files with 19 additions and 1 deletions
|
@ -372,8 +372,8 @@ class _Stream:
|
||||||
self.zlib = zlib
|
self.zlib = zlib
|
||||||
self.crc = zlib.crc32(b"")
|
self.crc = zlib.crc32(b"")
|
||||||
if mode == "r":
|
if mode == "r":
|
||||||
self._init_read_gz()
|
|
||||||
self.exception = zlib.error
|
self.exception = zlib.error
|
||||||
|
self._init_read_gz()
|
||||||
else:
|
else:
|
||||||
self._init_write_gz(compresslevel)
|
self._init_write_gz(compresslevel)
|
||||||
|
|
||||||
|
|
|
@ -938,6 +938,23 @@ class LzmaDetectReadTest(LzmaTest, DetectReadTest):
|
||||||
pass
|
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' # timestamp, compression data, OS ID
|
||||||
|
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):
|
class MemberReadTest(ReadTest, unittest.TestCase):
|
||||||
|
|
||||||
def _test_member(self, tarinfo, chksum=None, **kwargs):
|
def _test_member(self, tarinfo, chksum=None, **kwargs):
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
tarfiles; Fixed use before assignment of self.exception for gzip decompression
|
Loading…
Add table
Add a link
Reference in a new issue