Menu

#152 Zip: Archiving hangs, if there is no read permission on the file

v1.0 (example)
open
nobody
None
5
2021-03-18
2015-04-15
Mizuno
No

If you simply create two files and pack them, it's all right

$ touch 1
$ touch 2
$ 7za a 1.zip 1 2

7-Zip (a) [64] 9.38 beta Copyright (c) 1999-2014 Igor Pavlov 2015-01-03
p7zip Version 9.38.1 (locale=ru_RU.UTF-8,Utf16=on,HugeFiles=on,8 CPUs,ASM)
Scanning

Creating archive 1.zip

Compressing 1
Compressing 2

Everything is Ok

But if one file can not be read, then packing hangs

$ chmod 0000 2
$ 7za a 2.zip 1 2

7-Zip (a) [64] 9.38 beta Copyright (c) 1999-2014 Igor Pavlov 2015-01-03
p7zip Version 9.38.1 (locale=ru_RU.UTF-8,Utf16=on,HugeFiles=on,8 CPUs,ASM)
Scanning

Creating archive 2.zip

Compressing 1
Compressing 2

<hang></hang>

Tested in ubuntu and Centos 5
The problem occurs only when run as an unprivileged user. As root - all right

Discussion

  • md-work

    md-work - 2021-01-19

    Still a problem in p7zip-16.02.

    Proposal:
    The "WARNING: Permission denied" is good.
    But afterwards 7z should continue the compression for the readable files.
    And finally 7z should exit with an exit code != 0.

    Tested on openSUSE-15.2:

    7-Zip [64] 16.02 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-21
    p7zip Version 16.02 (locale=C,Utf16=off,HugeFiles=on,64 bits,2 CPUs QEMU Virtual CPU version 2.5+ (663),ASM)
    
    Open archive: ../rw/test.zip
    --
    Path = ../rw/test.zip
    Type = zip
    Physical Size = 22
    
    Scanning the drive:
    2 files, 0 bytes
    
    Updating archive: ../rw/test.zip
    
    Items to compress: 2
    
    
    WARNING: Permission denied
    2
    
     
  • Sam Tansy

    Sam Tansy - 2021-03-18

    Only with zip files though. When using 7z it's fine, program ignores inaccessible file and moves on.

    $ echo -n "1" > 1; echo -n "22" > 22
    $ chmod 0000 22
    $ rm *.7z; ./7za a 12b.7z 1 22
    
    
    Scanning the drive:
    2 files, 3 bytes (1 KiB)
    
    Creating archive: 12b.7z
    
    Items to compress: 2
    
    
    WARNING: Permission denied
    22
    
    
    Files read from disk: 2
    Archive size: 134 bytes (1 KiB)
    
    WARNINGS for files:
    
    22 : Permission denied
    ----------------
    WARNING: Cannot open 1 file
    

    Back to the problem, I tried to use gdb and strace and all I found put is this:
    in gdb program hangs in libpthreads.so:

    $(gdb)
    Program received signal SIGINT, Interrupt.
    0xb7fbbfed in ?? () from /lib/libpthread.so.0
    (gdb) bt
    #0  0xb7fbbfed in ?? () from /lib/libpthread.so.0
    #1  0xb7fb7bf9 in ?? () from /lib/libpthread.so.0
    Backtrace stopped: previous frame identical to this frame (corrupt stack?)
    (gdb) where
    #0  0xb7fbbfed in ?? () from /lib/libpthread.so.0
    #1  0xb7fb7bf9 in ?? () from /lib/libpthread.so.0
    Backtrace stopped: previous frame identical to this frame (corrupt stack?)
    

    and strace somewhere here:

    clone(child_stack=0xb288f424, flags=CLONE_VM|CLONE_FS|CLONE_FILES|CLONE_SIGHAND|CLONE_THREAD|CLONE_SYSVSEM|CLONE_SETTLS|CLONE_PARENT_SETTID|CLONE_CHILD_CLEARTID, parent_tidptr=0xb288fba8, {entry_number:6, base_addr:0xb288fb40, limit:1048575, seg_32bit:1, contents:0, read_exec_only:0, limit_in_pages:1, seg_not_present:0, useable:1}, child_tidptr=0xb288fba8) = 12714
    gettimeofday({1616099717, 264583}, NULL) = 0
    umask(0)                                = 022
    umask(022)                              = 0
    readlink("1", 0x8682358, 1024)          = -1 EINVAL (Invalid argument)
    open("1", O_RDONLY|O_LARGEFILE)         = 4
    gettimeofday({1616099717, 264872}, NULL) = 0
    umask(0)                                = 022
    umask(022)                              = 0
    readlink("22", 0x8682838, 1024)         = -1 EINVAL (Invalid argument)
    open("22", O_RDONLY|O_LARGEFILE)        = -1 EACCES (Permission denied)
    write(1, "\10\10\10\10    \10\10\10\10") = 12
    write(2, "\n", 1
    )                       = 1
    write(2, "WARNING: ", 9WARNING: )                = 9
    write(2, "Permission denied", 17Permission denied)       = 17
    write(2, "\n", 1
    )                       = 1
    write(2, "22", 222)                       = 2
    write(2, "\n", 1
    )                       = 1
    write(2, "\n", 1
    )                       = 1
    futex(0x8681dcc, FUTEX_WAIT_PRIVATE, 2, NULL
    ^C <unfinished ...>
    

    which again made me think it has something to do with threads, so I made an experiment:

    $ echo -n "1" > 1; echo -n "22" > 22
    $ chmod 0000 22
    $ rm *.zip; ./7za a -mmt1 12b.zip 1 22
    
    Scanning the drive:
    2 files, 3 bytes (1 KiB)
    
    Creating archive: 12b.zip
    
    Items to compress: 2
    
    
    WARNING: Permission denied
    22
    
    
    Files read from disk: 2
    Archive size: 137 bytes (1 KiB)
    
    WARNINGS for files:
    
    22 : Permission denied
    ----------------
    WARNING: Cannot open 1 file
    
    $ ls -l *.zip 
    -rw-r--r-- 1 user users 137 Mar 18 22:11 12b.zip
    
    $ 7z l 12b.zip
    
    Listing archive: 12b.zip
    
    --
    Path = 12b.zip
    Type = zip
    Physical Size = 137
    
       Date      Time    Attr         Size   Compressed  Name
    ------------------- ----- ------------ ------------  ------------------------
    2021-03-18 19:17:03 .....            1            1  1
    ------------------- ----- ------------ ------------  ------------------------
    2021-03-18 19:17:03                  1            1  1 files
    

    And it looks like I was right. When one turns off multiple treads, it works fine.

    It obviously doesn't solve the problem but gives the hint where to look for.

     

    Last edit: Sam Tansy 2021-03-24

Log in to post a comment.

MongoDB Logo MongoDB