tarfile seems to incorrectly handle filenames longer
than 100 characters. This is tarfile as provided with
2.4.3 and 2.4.4. The 0.8.0 version of tarfile is even
worse - it will cut off the last character of any
filename that is exactly 100 in size.
Below the unit test that I use to reproduce the problem:
class Test00tarfile(unittest.TestCase):
def runtest(self, longName):
import tarfile
dst=StringIO()
src=StringIO("Hello world!")
srclen = len("Hello world!")
tar = tarfile.open(mode='w|', fileobj=dst)
tar.add('test.py')
info = tar.gettarinfo('test.py', longName)
info.size = srclen
tar.addfile(info, src)
src.seek(0)
tar.addfile(info, src)
tar.close()
dst.seek(0)
tar = tarfile.open(mode='r|', fileobj=dst)
info = tar.next()
self.assertEqual(info.name, 'test.py')
info = tar.next()
self.assertEqual(info.size, srclen)
self.assertEqual(info.name, longName)
info = tar.next()
self.assertEqual(info.name, longName)
info = tar.next()
self.assertEqual(None, info)
def testLongFileName200(self):
"tarfile with 200+ length filename"
self.runtest("LongName/" + 200 * "x" + "/LongTail")
def testLongFileName100(self):
"tarfile with 100 length filename"
self.runtest('MyWiki/underlay/pages/(e7ae80e4bd93e4b8ade69687)MoinMoin(2fe5ae89e8a385e6898be5868c)/cache/text_html')
The "200" test fails on the standard version, on
tarfile 0.8.0 the 100 test fails too.
|