mirror of
https://github.com/python/cpython.git
synced 2025-08-09 19:38:42 +00:00
[3.9] bpo-39039: tarfile raises descriptive exception from zlib.error (GH-27766) (GH-28614)
* 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.
(cherry picked from commit b6fe857250
)
Co-authored-by: Jack DeVries <58614260+jdevries3133@users.noreply.github.com>
This commit is contained in:
parent
c6b5ceae34
commit
7bff4d396f
3 changed files with 25 additions and 0 deletions
|
@ -2345,6 +2345,15 @@ class TarFile(object):
|
|||
raise ReadError(str(e))
|
||||
except SubsequentHeaderError as e:
|
||||
raise ReadError(str(e))
|
||||
except Exception as e:
|
||||
try:
|
||||
import zlib
|
||||
if isinstance(e, zlib.error):
|
||||
raise ReadError(f'zlib error: {e}')
|
||||
else:
|
||||
raise e
|
||||
except ImportError:
|
||||
raise e
|
||||
break
|
||||
|
||||
if tarinfo is not None:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue