Patch #1262036: Prevent TarFiles from being added to themselves under
certain conditions.
(backport from rev. 53155)
Moved message from my previous change to the right place in
Misc/NEWS.
diff --git a/Lib/test/test_tarfile.py b/Lib/test/test_tarfile.py
index f229fa5..fbcd191 100644
--- a/Lib/test/test_tarfile.py
+++ b/Lib/test/test_tarfile.py
@@ -290,6 +290,20 @@
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.