summaryrefslogtreecommitdiff
path: root/Lib/test/test_tarfile.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2006-12-20 11:55:16 +0000
committerGeorg Brandl <georg@python.org>2006-12-20 11:55:16 +0000
commitded1c4df0b98b05af22d82bd8ae8795f7c8da916 (patch)
tree279ed70caa94a6e534ac1318b024ed73a06a5656 /Lib/test/test_tarfile.py
parent94547f7646895e032f8fc145529d9efc3a70760d (diff)
downloadcpython-git-ded1c4df0b98b05af22d82bd8ae8795f7c8da916.tar.gz
Testcase for patch #1484695.
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 2685d67819..56cc919e93 100644
--- a/Lib/test/test_tarfile.py
+++ b/Lib/test/test_tarfile.py
@@ -601,6 +601,28 @@ class FileModeTest(unittest.TestCase):
self.assertEqual(tarfile.filemode(0755), '-rwxr-xr-x')
self.assertEqual(tarfile.filemode(07111), '---s--s--t')
+class HeaderErrorTest(unittest.TestCase):
+
+ def test_truncated_header(self):
+ self.assertRaises(tarfile.HeaderError, tarfile.TarInfo.frombuf, "")
+ self.assertRaises(tarfile.HeaderError, tarfile.TarInfo.frombuf, "filename\0")
+ self.assertRaises(tarfile.HeaderError, tarfile.TarInfo.frombuf, "\0" * 511)
+ self.assertRaises(tarfile.HeaderError, tarfile.TarInfo.frombuf, "\0" * 513)
+
+ def test_empty_header(self):
+ self.assertRaises(tarfile.HeaderError, tarfile.TarInfo.frombuf, "\0" * 512)
+
+ def test_invalid_header(self):
+ buf = tarfile.TarInfo("filename").tobuf()
+ buf = buf[:148] + "foo\0\0\0\0\0" + buf[156:] # invalid number field.
+ self.assertRaises(tarfile.HeaderError, tarfile.TarInfo.frombuf, buf)
+
+ def test_bad_checksum(self):
+ buf = tarfile.TarInfo("filename").tobuf()
+ b = buf[:148] + " " + buf[156:] # clear the checksum field.
+ self.assertRaises(tarfile.HeaderError, tarfile.TarInfo.frombuf, b)
+ b = "a" + buf[1:] # manipulate the buffer, so checksum won't match.
+ self.assertRaises(tarfile.HeaderError, tarfile.TarInfo.frombuf, b)
if bz2:
# Bzip2 TestCases
@@ -646,6 +668,7 @@ def test_main():
tests = [
FileModeTest,
+ HeaderErrorTest,
ReadTest,
ReadStreamTest,
ReadDetectTest,