summaryrefslogtreecommitdiff
path: root/Lib/tarfile.py
diff options
context:
space:
mode:
authorƁukasz Langa <lukasz@langa.pl>2021-09-29 12:19:37 +0200
committerGitHub <noreply@github.com>2021-09-29 12:19:37 +0200
commitd6b69f21d8ec4af47a9c79f3f50d20be3d0875fc (patch)
tree693a309ab231f456b057448c7c63915400402c71 /Lib/tarfile.py
parent1cb17be3e6a4d94629606a613acd07f78d50348b (diff)
downloadcpython-git-d6b69f21d8ec4af47a9c79f3f50d20be3d0875fc.tar.gz
[3.10] bpo-39039: tarfile raises descriptive exception from zlib.error (GH-27766) (GH-28613)
* 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 b6fe8572509b77d2002eaddf99d718e9b4835684) Co-authored-by: Jack DeVries <58614260+jdevries3133@users.noreply.github.com>
Diffstat (limited to 'Lib/tarfile.py')
-rwxr-xr-xLib/tarfile.py9
1 files changed, 9 insertions, 0 deletions
diff --git a/Lib/tarfile.py b/Lib/tarfile.py
index 18d415adf5..c1ee1222e0 100755
--- a/Lib/tarfile.py
+++ b/Lib/tarfile.py
@@ -2349,6 +2349,15 @@ class TarFile(object):
raise ReadError(str(e)) from None
except SubsequentHeaderError as e:
raise ReadError(str(e)) from None
+ except Exception as e:
+ try:
+ import zlib
+ if isinstance(e, zlib.error):
+ raise ReadError(f'zlib error: {e}') from None
+ else:
+ raise e
+ except ImportError:
+ raise e
break
if tarinfo is not None: