[Python-checkins] r52431 - in python/trunk/Lib: tarfile.py test/test_tarfile.py
georg.brandl
python-checkins at python.org
Tue Oct 24 18:54:20 CEST 2006
Author: georg.brandl
Date: Tue Oct 24 18:54:16 2006
New Revision: 52431
Modified:
python/trunk/Lib/tarfile.py
python/trunk/Lib/test/test_tarfile.py
Log:
Patch [ 1583506 ] tarfile.py: 100-char filenames are truncated
Modified: python/trunk/Lib/tarfile.py
==============================================================================
--- python/trunk/Lib/tarfile.py (original)
+++ python/trunk/Lib/tarfile.py Tue Oct 24 18:54:16 2006
@@ -136,7 +136,7 @@
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.
Modified: python/trunk/Lib/test/test_tarfile.py
==============================================================================
--- python/trunk/Lib/test/test_tarfile.py (original)
+++ python/trunk/Lib/test/test_tarfile.py Tue Oct 24 18:54:16 2006
@@ -280,6 +280,32 @@
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 @@
ReadAsteriskTest,
ReadStreamAsteriskTest,
WriteTest,
+ Write100Test,
WriteSize0Test,
WriteStreamTest,
WriteGNULongTest,
More information about the Python-checkins
mailing list