mirror of
https://github.com/python/cpython.git
synced 2025-10-21 22:22:48 +00:00
Merge with 3.4: Issue #24259: tarfile now raises a ReadError if an archive is truncated inside a data segment.
This commit is contained in:
commit
e12aa62d68
3 changed files with 41 additions and 7 deletions
|
@ -364,6 +364,29 @@ class CommonReadTest(ReadTest):
|
|||
finally:
|
||||
tar.close()
|
||||
|
||||
def test_premature_end_of_archive(self):
|
||||
for size in (512, 600, 1024, 1200):
|
||||
with tarfile.open(tmpname, "w:") as tar:
|
||||
t = tarfile.TarInfo("foo")
|
||||
t.size = 1024
|
||||
tar.addfile(t, io.BytesIO(b"a" * 1024))
|
||||
|
||||
with open(tmpname, "r+b") as fobj:
|
||||
fobj.truncate(size)
|
||||
|
||||
with tarfile.open(tmpname) as tar:
|
||||
with self.assertRaisesRegex(tarfile.ReadError, "unexpected end of data"):
|
||||
for t in tar:
|
||||
pass
|
||||
|
||||
with tarfile.open(tmpname) as tar:
|
||||
t = tar.next()
|
||||
|
||||
with self.assertRaisesRegex(tarfile.ReadError, "unexpected end of data"):
|
||||
tar.extract(t, TEMPDIR)
|
||||
|
||||
with self.assertRaisesRegex(tarfile.ReadError, "unexpected end of data"):
|
||||
tar.extractfile(t).read()
|
||||
|
||||
class MiscReadTestBase(CommonReadTest):
|
||||
def requires_name_attribute(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue