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 extraction does not honor umask
Type: Stage:
Components: Library (Lib) Versions: Python 2.5
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: lars.gustaebel Nosy List: faik, hanwen, lars.gustaebel
Priority: normal Keywords: patch

Created on 2006-06-16 12:11 by faik, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
python-2.4.3-tarfile-umask.patch faik, 2006-08-18 09:44 tarfile umask patch
makedirs.diff lars.gustaebel, 2006-12-31 11:52
Messages (7)
msg50488 - (view) Author: Faik Uygur (faik) Date: 2006-06-16 12:11
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
msg50489 - (view) Author: Faik Uygur (faik) Date: 2006-08-18 09:44
Logged In: YES 
user_id=1541018

Above patch is wrong. The correct one is attached.
msg50490 - (view) Author: Han-Wen Nienhuys (hanwen) * Date: 2006-12-05 23:40
Hi, 

I can reproduce this problem on python 2.4 , and patch applies to python 2.5 too. Fix looks good to me.
msg50491 - (view) Author: Lars Gustäbel (lars.gustaebel) * (Python committer) Date: 2006-12-30 12:11
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?
msg50492 - (view) Author: Han-Wen Nienhuys (hanwen) * Date: 2006-12-30 18:25
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.


msg50493 - (view) Author: Lars Gustäbel (lars.gustaebel) * (Python committer) Date: 2006-12-31 11:52
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
msg50494 - (view) Author: Lars Gustäbel (lars.gustaebel) * (Python committer) Date: 2007-01-23 11:18
Committed my patch as rev. 53526.
History
Date User Action Args
2022-04-11 14:56:18adminsetgithub: 43515
2006-06-16 12:11:19faikcreate