This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: tarfile incorrectly handles long filenames
Type: Stage:
Components: Library (Lib) Versions: Python 2.4
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: cdwave
Priority: normal Keywords:

Created on 2006-10-24 12:05 by cdwave, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
test_tarfile.py cdwave, 2006-10-24 12:16 Test demonstrating the problem
Messages (2)
msg30379 - (view) Author: Mike Looijmans (cdwave) Date: 2006-10-24 12:05
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.
msg30380 - (view) Author: Mike Looijmans (cdwave) Date: 2006-10-24 13:33
Logged In: YES 
user_id=1372511

Test was wrong, and there were distinct bugs in various
versions.
History
Date User Action Args
2022-04-11 14:56:20adminsetgithub: 44161
2006-10-24 12:05:52cdwavecreate