mirror of
https://github.com/python/cpython.git
synced 2025-11-02 11:08:57 +00:00
bpo-39039: tarfile raises descriptive exception from zlib.error (GH-27766)
* during tarfile parsing, a zlib error indicates invalid data * tarfile.open now raises a descriptive exception from the zlib error * this makes it clear to the user that they may be trying to open a corrupted tar file
This commit is contained in:
parent
233b9da07d
commit
b6fe857250
3 changed files with 25 additions and 0 deletions
|
|
@ -19,6 +19,10 @@ try:
|
|||
import gzip
|
||||
except ImportError:
|
||||
gzip = None
|
||||
try:
|
||||
import zlib
|
||||
except ImportError:
|
||||
zlib = None
|
||||
try:
|
||||
import bz2
|
||||
except ImportError:
|
||||
|
|
@ -687,6 +691,16 @@ class MiscReadTestBase(CommonReadTest):
|
|||
self.assertEqual(m1.offset, m2.offset)
|
||||
self.assertEqual(m1.get_info(), m2.get_info())
|
||||
|
||||
@unittest.skipIf(zlib is None, "requires zlib")
|
||||
def test_zlib_error_does_not_leak(self):
|
||||
# bpo-39039: tarfile.open allowed zlib exceptions to bubble up when
|
||||
# parsing certain types of invalid data
|
||||
with unittest.mock.patch("tarfile.TarInfo.fromtarfile") as mock:
|
||||
mock.side_effect = zlib.error
|
||||
with self.assertRaises(tarfile.ReadError):
|
||||
tarfile.open(self.tarname)
|
||||
|
||||
|
||||
class MiscReadTest(MiscReadTestBase, unittest.TestCase):
|
||||
test_fail_comp = None
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue