]> granicus.if.org Git - python/commitdiff
Issue #12841: Fix tarfile extraction of non-existent uids/gids.
authorLars Gustäbel <lars@gustaebel.de>
Mon, 5 Sep 2011 15:04:18 +0000 (17:04 +0200)
committerLars Gustäbel <lars@gustaebel.de>
Mon, 5 Sep 2011 15:04:18 +0000 (17:04 +0200)
tarfile unnecessarily checked the existence of numerical user and group ids on
extraction. If one of them did not exist the respective id of the current user
(i.e. root) was used for the file and ownership information was lost. (Patch
by Sebastien Luttringer)

Lib/tarfile.py
Misc/NEWS

index 112b419da8e5416d974a8ba7a684a707443eeec4..6828eab5a5d06e1eb8a5ad6c2c914723d36a417f 100644 (file)
@@ -2264,17 +2264,11 @@ class TarFile(object):
             try:
                 g = grp.getgrnam(tarinfo.gname)[2]
             except KeyError:
-                try:
-                    g = grp.getgrgid(tarinfo.gid)[2]
-                except KeyError:
-                    g = os.getgid()
+                g = tarinfo.gid
             try:
                 u = pwd.getpwnam(tarinfo.uname)[2]
             except KeyError:
-                try:
-                    u = pwd.getpwuid(tarinfo.uid)[2]
-                except KeyError:
-                    u = os.getuid()
+                u = tarinfo.uid
             try:
                 if tarinfo.issym() and hasattr(os, "lchown"):
                     os.lchown(targetpath, u, g)
index 6d57532578ac0e7a089590ad155c59eb05153d78..b286f8b5827d4781ef6345b4ea23149b70495786 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -40,6 +40,11 @@ Core and Builtins
 Library
 -------
 
+- Issue #12841: tarfile unnecessarily checked the existence of numerical user
+  and group ids on extraction. If one of them did not exist the respective id
+  of the current user (i.e. root) was used for the file and ownership
+  information was lost.
+
 - Issue #10946: The distutils commands bdist_dumb, bdist_wininst and bdist_msi
   now respect a --skip-build option given to bdist.