diff options
author | Georg Brandl <georg@python.org> | 2006-10-24 16:54:23 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2006-10-24 16:54:23 (GMT) |
commit | ee23f4bba73f704b59c590a94b4731a22b72c7e7 (patch) | |
tree | 4f7d0e6391ef87221e16a1d29534bbe4592d9dcd /Lib | |
parent | 920fa6a102f8d5f46a2e0552e85ae295882a92bb (diff) | |
download | cpython-ee23f4bba73f704b59c590a94b4731a22b72c7e7.zip cpython-ee23f4bba73f704b59c590a94b4731a22b72c7e7.tar.gz cpython-ee23f4bba73f704b59c590a94b4731a22b72c7e7.tar.bz2 |
Patch [ 1583506 ] tarfile.py: 100-char filenames are truncated
(backport from rev. 52431)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/tarfile.py | 2 | ||||
-rw-r--r-- | Lib/test/test_tarfile.py | 27 |
2 files changed, 28 insertions, 1 deletions
diff --git a/Lib/tarfile.py b/Lib/tarfile.py index 8d5f021..7c140da 100644 --- a/Lib/tarfile.py +++ b/Lib/tarfile.py @@ -136,7 +136,7 @@ TOEXEC = 0001 # execute/search by other def stn(s, length): """Convert a python string to a null-terminated string buffer. """ - return s[:length-1] + (length - len(s) - 1) * NUL + NUL + return s[:length] + (length - len(s)) * NUL def nti(s): """Convert a number field to a python number. diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py index ebcb8c5..ee83cbe 100644 --- a/Lib/test/test_tarfile.py +++ b/Lib/test/test_tarfile.py @@ -280,6 +280,32 @@ class WriteTest(BaseTest): else: self.dst.addfile(tarinfo, f) + +class Write100Test(BaseTest): + # The name field in a tar header stores strings of at most 100 chars. + # If a string is shorter than 100 chars it has to be padded with '\0', + # which implies that a string of exactly 100 chars is stored without + # a trailing '\0'. + + def setUp(self): + self.name = "01234567890123456789012345678901234567890123456789" + self.name += "01234567890123456789012345678901234567890123456789" + + self.tar = tarfile.open(tmpname(), "w") + t = tarfile.TarInfo(self.name) + self.tar.addfile(t) + self.tar.close() + + self.tar = tarfile.open(tmpname()) + + def tearDown(self): + self.tar.close() + + def test(self): + self.assertEqual(self.tar.getnames()[0], self.name, + "failed to store 100 char filename") + + class WriteSize0Test(BaseTest): mode = 'w' @@ -623,6 +649,7 @@ def test_main(): ReadAsteriskTest, ReadStreamAsteriskTest, WriteTest, + Write100Test, WriteSize0Test, WriteStreamTest, WriteGNULongTest, |