New submission from Yujie Chen:
I have seen a similar ticket, however that was opened 2 years ago and has
nothing more than a brief description. So I opened this new one here, hoping to
get some answers.
tarfile.TarFile object is iterable and has a next() method. next() will parse
the header and save parsed info. During parsing, a lot of checks are done, to
make sure the header is valid. And if there is something wrong with the header,
exceptions will be thrown. next() catches a lot of them but not reraise what it
catches in all cases.
I have a tgz file, one of the headers is corrupted with a wrong checksum
section. thus during parsing, InvalidHeaderError was thrown. next() catches
that but hide it silently. From source code
(https://hg.python.org/cpython/file/2.7/Lib/tarfile.py#l2335), we can see that
InvalidHeaderError will ONLY be raised if it happens in the beginning of the
tar file. Actually, a lot of exceptions are hidden by tarfile module. tarfile
module simply thinks these exceptions mark the end of tarball.
Why does tarfile module hide so many exceptions? or in other words, why does
tarfile treat these exceptions as the end marker of tarball but not errors?
Is it because of this from GNU doc:
"At the end of the archive file there are two 512-byte blocks filled with
binary zeros as an end-of-file marker. A reasonable system should write such
end-of-file marker at the end of an archive, but must not assume that such a
block exists when reading an archive."?
Thanks!
--
components: Library (Lib)
messages: 270990
nosy: JieGhost
priority: normal
severity: normal
status: open
title: tarfile module next() method hides exceptions
type: behavior
versions: Python 2.7
___
Python tracker
<http://bugs.python.org/issue27590>
___
___
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com