Patch #1262036: Prevent TarFiles from being added to themselves under

certain conditions.

Will backport to 2.5.
This commit is contained in:
Lars Gustäbel 2006-12-23 17:57:23 +00:00
parent 6baa502769
commit a4b2381b20
3 changed files with 23 additions and 27 deletions

View file

@ -290,6 +290,20 @@ class WriteTest(BaseTest):
else:
self.dst.addfile(tarinfo, f)
def test_add_self(self):
dstname = os.path.abspath(self.dstname)
self.assertEqual(self.dst.name, dstname, "archive name must be absolute")
self.dst.add(dstname)
self.assertEqual(self.dst.getnames(), [], "added the archive to itself")
cwd = os.getcwd()
os.chdir(dirname())
self.dst.add(dstname)
os.chdir(cwd)
self.assertEqual(self.dst.getnames(), [], "added the archive to itself")
class Write100Test(BaseTest):
# The name field in a tar header stores strings of at most 100 chars.