[Patches] [ python-Patches-1507247 ] tarfile extraction does not honor umask

SourceForge.net noreply at sourceforge.net
Sun Dec 31 12:52:05 CET 2006


Patches item #1507247, was opened at 2006-06-16 14:11
Message generated for change (Comment added) made by gustaebel
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1507247&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Library (Lib)
Group: Python 2.5
Status: Open
Resolution: None
Priority: 5
Private: No
Submitted By: Faik Uygur (faik)
Assigned to: Lars Gustäbel (gustaebel)
Summary: tarfile extraction does not honor umask

Initial Comment:
If the upperdirs in the member file's pathname does not 
exist. tarfile creates those paths with 0777 permission 
bits and does not honor umask.

This patch uses umask to set the ti.mode of the created 
directory for later usage in chmod.

--- tarfile.py  (revision 46993)
+++ tarfile.py  (working copy)
@@ -1560,7 +1560,9 @@
             ti = TarInfo()
             ti.name  = upperdirs
             ti.type  = DIRTYPE
-            ti.mode  = 0777
+            umask = os.umask(0)
+            ti.mode  = 0777 - umask
+            os.umask(umask)
             ti.mtime = tarinfo.mtime
             ti.uid   = tarinfo.uid
             ti.gid   = tarinfo.gid


----------------------------------------------------------------------

>Comment By: Lars Gustäbel (gustaebel)
Date: 2006-12-31 12:52

Message:
Logged In: YES 
user_id=642936
Originator: NO

I've come to the conclusion that it is a doubtful approach to take the
mtime and ownership from the file and use it on the upper directories as
well. So, I've come up with a totally different solution (cp.
makedirs.diff) that abandons the use of os.umask() completely and uses a
single call to os.makedirs() to create the missing directories.
It seems very attractive to me to do it this way, what do you think?
File Added: makedirs.diff

----------------------------------------------------------------------

Comment By: Han-Wen Nienhuys (hanwen)
Date: 2006-12-30 19:25

Message:
Logged In: YES 
user_id=161998
Originator: NO

umask(2) works in the same way, so there seems to be no unixy way to
inspect umask without setting it.
I think the solution would be to make a C-level function to return the
umask (by setting and resetting it). 
As the interpreter itself is single threaded, this is race-free.




----------------------------------------------------------------------

Comment By: Lars Gustäbel (gustaebel)
Date: 2006-12-30 13:11

Message:
Logged In: YES 
user_id=642936
Originator: NO

In order to determine the current umask we have no other choice AFAIK than
to set it with a bogus value, save the return value and restore it right
away - as you proposed in your patch. The problem is that there is a small
window of time between these two calls where the umask is invalid. This is
especially bad in multi-threaded environments.

Any ideas?

----------------------------------------------------------------------

Comment By: Han-Wen Nienhuys (hanwen)
Date: 2006-12-06 00:40

Message:
Logged In: YES 
user_id=161998
Originator: NO

Hi, 

I can reproduce this problem on python 2.4 , and patch applies to python
2.5 too. Fix looks good to me.


----------------------------------------------------------------------

Comment By: Faik Uygur (faik)
Date: 2006-08-18 11:44

Message:
Logged In: YES 
user_id=1541018

Above patch is wrong. The correct one is attached.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=305470&aid=1507247&group_id=5470


More information about the Patches mailing list