summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_tarfile.py
diff options
context:
space:
mode:
authorLars Gustäbel <lars@gustaebel.de>2015-07-06 07:27:24 (GMT)
committerLars Gustäbel <lars@gustaebel.de>2015-07-06 07:27:24 (GMT)
commit0357268d96d4ff3546cfd89f594a5630a3adf747 (patch)
treee4a4869b686c5d72e546c24cbee377b6fcfcb407 /Lib/test/test_tarfile.py
parent54630d999f640b3ea0b9da302a112a0ccd5bdd96 (diff)
downloadcpython-0357268d96d4ff3546cfd89f594a5630a3adf747.zip
cpython-0357268d96d4ff3546cfd89f594a5630a3adf747.tar.gz
cpython-0357268d96d4ff3546cfd89f594a5630a3adf747.tar.bz2
Issue #24259: tarfile now raises a ReadError if an archive is truncated inside a data segment.
Diffstat (limited to 'Lib/test/test_tarfile.py')
-rw-r--r--Lib/test/test_tarfile.py23
1 files changed, 23 insertions, 0 deletions
diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py
index 5b55e07..8ab7575 100644
--- a/Lib/test/test_tarfile.py
+++ b/Lib/test/test_tarfile.py
@@ -349,6 +349,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):