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 creates tarballs with execute permissions set
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.1, Python 3.2, Python 2.7, Python 2.6, Python 2.5
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: lars.gustaebel Nosy List: l0nwlf, lars.gustaebel, mastrodomenico, tarek
Priority: normal Keywords: patch

Created on 2010-04-19 17:38 by mastrodomenico, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
tarfile.diff mastrodomenico, 2010-04-19 17:38 patch for the trunk
Messages (5)
msg103617 - (view) Author: Lino Mastrodomenico (mastrodomenico) Date: 2010-04-19 17:38
tarfile.open(filename, "w|") creates a tar file with execute permissions set, if filename doesn't exist (i.e. it uses mode 0777 minus the umask). It should instead use mode 0666 minus the umask, which is what happens when using mode "w:..." instead of "w|...".

AFAICT this bug has always been present since the introduction of tarfile in Python 2.3, but it may soon become more noticeable since the new function shutil.make_archive() in Python 2.7 and 3.2 uses tarfile with mode "w|".

I have attached a patch for the trunk.
msg103623 - (view) Author: Shashwat Anand (l0nwlf) Date: 2010-04-19 18:53
Is "self.fd = os.open(name, mode, 0666)" Ok ? Should not it be "self.fd = os.open(name, mode, 0644)", because that is what the default permissions are.
msg103633 - (view) Author: Lino Mastrodomenico (mastrodomenico) Date: 2010-04-19 20:19
I think 0666 is correct because os.open() does a bitwise AND between this value and the bitwise inversion of the umask, something like oct(0666 & ~umask).

Since the umask is usually 022 octal (18 decimal), the actual permission on disk should be 0644 as expected.
msg103679 - (view) Author: Lars Gustäbel (lars.gustaebel) * (Python committer) Date: 2010-04-20 07:11
0666 is the right mode and the patch is correct.

@Tarek: Why does shutil.make_archive() use mode "w|..." instead of "w:..."? IMHO that is not necessary, because it works on regular files only.
msg104526 - (view) Author: Lars Gustäbel (lars.gustaebel) * (Python committer) Date: 2010-04-29 15:45
I applied the patch and added a test case (see r80616-r80619). Thanks for the report.
History
Date User Action Args
2022-04-11 14:57:00adminsetgithub: 52710
2010-04-29 15:45:43lars.gustaebelsetstatus: open -> closed
resolution: accepted
messages: + msg104526

stage: resolved
2010-04-20 07:11:01lars.gustaebelsetmessages: + msg103679
2010-04-19 21:21:36tareksetassignee: lars.gustaebel

nosy: + lars.gustaebel
2010-04-19 20:19:26mastrodomenicosetmessages: + msg103633
2010-04-19 18:56:34l0nwlfsetnosy: + tarek
2010-04-19 18:53:51l0nwlfsetnosy: + l0nwlf
messages: + msg103623
2010-04-19 17:38:59mastrodomenicocreate