gh-156057: Wrap compression library exceptions in tarfile.ReadError (GH-156143)
_FileInFile.read() (used by TarFile.extractfile() for seekable-mode
archives) called the underlying compressed fileobj's read() directly.
If a member's compressed payload was corrupted after the header had
already been read successfully, the codec's own exception (zlib.error,
OSError from bz2, lzma.LZMAError, or zstd.ZstdError) would leak straight
through instead of being wrapped in tarfile.ReadError, unlike the
existing streaming-mode (r|gz etc.) code path in _Stream, which already
handles this correctly via a self.exception attribute set per codec.
Give TarFile (and _FileInFile) the same per-codec exception attribute,
set by gzopen/xzopen/zstopen to the specific error type (bz2 already
matches the OSError class default), and wrap the read() call in
_FileInFile with it.
---------
Signed-off-by: Jason Mak <squrrielbro@gmail.com>
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
3 files changed