summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_tarfile.py
diff options
context:
space:
mode:
authorLars Gustäbel <lars@gustaebel.de>2015-07-06 07:32:05 (GMT)
committerLars Gustäbel <lars@gustaebel.de>2015-07-06 07:32:05 (GMT)
commit7afe40e40ea045b08f9baf6c8c56d642b385c973 (patch)
tree3a914157c1e09cdd191b93450c565ab67f621e47 /Lib/test/test_tarfile.py
parentb48d6a63ffdba18a0fab80f3458632dcf01e2bea (diff)
parente12aa62d689f435b9b75cde51e432d997646d5f9 (diff)
downloadcpython-7afe40e40ea045b08f9baf6c8c56d642b385c973.zip
cpython-7afe40e40ea045b08f9baf6c8c56d642b385c973.tar.gz
cpython-7afe40e40ea045b08f9baf6c8c56d642b385c973.tar.bz2
Merge with 3.5: 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 0f03c73..57cddb2 100644
--- a/Lib/test/test_tarfile.py
+++ b/Lib/test/test_tarfile.py
@@ -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):