Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tarfile extraction does not honor umask #43515

Closed
faik mannequin opened this issue Jun 16, 2006 · 7 comments
Closed

tarfile extraction does not honor umask #43515

faik mannequin opened this issue Jun 16, 2006 · 7 comments
Assignees
Labels
stdlib Python modules in the Lib dir

Comments

@faik
Copy link
Mannequin

faik mannequin commented Jun 16, 2006

BPO 1507247
Nosy @gustaebel
Files
  • python-2.4.3-tarfile-umask.patch: tarfile umask patch
  • makedirs.diff
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = 'https://github.com/gustaebel'
    closed_at = <Date 2007-01-23.11:18:39.000>
    created_at = <Date 2006-06-16.12:11:19.000>
    labels = ['library']
    title = 'tarfile extraction does not honor umask'
    updated_at = <Date 2007-01-23.11:18:39.000>
    user = 'https://bugs.python.org/faik'

    bugs.python.org fields:

    activity = <Date 2007-01-23.11:18:39.000>
    actor = 'lars.gustaebel'
    assignee = 'lars.gustaebel'
    closed = True
    closed_date = None
    closer = None
    components = ['Library (Lib)']
    creation = <Date 2006-06-16.12:11:19.000>
    creator = 'faik'
    dependencies = []
    files = ['7332', '7333']
    hgrepos = []
    issue_num = 1507247
    keywords = ['patch']
    message_count = 7.0
    messages = ['50488', '50489', '50490', '50491', '50492', '50493', '50494']
    nosy_count = 3.0
    nosy_names = ['hanwen', 'lars.gustaebel', 'faik']
    pr_nums = []
    priority = 'normal'
    resolution = 'accepted'
    stage = None
    status = 'closed'
    superseder = None
    type = None
    url = 'https://bugs.python.org/issue1507247'
    versions = ['Python 2.5']

    @faik
    Copy link
    Mannequin Author

    faik mannequin commented Jun 16, 2006

    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

    @faik faik mannequin closed this as completed Jun 16, 2006
    @faik faik mannequin assigned gustaebel Jun 16, 2006
    @faik faik mannequin added the stdlib Python modules in the Lib dir label Jun 16, 2006
    @faik faik mannequin closed this as completed Jun 16, 2006
    @faik faik mannequin assigned gustaebel Jun 16, 2006
    @faik faik mannequin added the stdlib Python modules in the Lib dir label Jun 16, 2006
    @faik
    Copy link
    Mannequin Author

    faik mannequin commented Aug 18, 2006

    Logged In: YES
    user_id=1541018

    Above patch is wrong. The correct one is attached.

    @hanwen
    Copy link
    Mannequin

    hanwen mannequin commented Dec 5, 2006

    Hi,

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

    @gustaebel
    Copy link
    Mannequin

    gustaebel mannequin commented Dec 30, 2006

    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?

    @hanwen
    Copy link
    Mannequin

    hanwen mannequin commented Dec 30, 2006

    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.

    @gustaebel
    Copy link
    Mannequin

    gustaebel mannequin commented Dec 31, 2006

    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

    @gustaebel
    Copy link
    Mannequin

    gustaebel mannequin commented Jan 23, 2007

    Committed my patch as rev. 53526.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir
    Projects
    None yet
    Development

    No branches or pull requests

    0 participants