Tcl Library Source Code

Ticket Change Details
Login
Overview

Artifact ID: 6d407ad805b12e7d5d0414c375626744901d273b23989a3bde9b009684698c64
Ticket: a0cbdc7e6f4a977e4c24b5a1a5c0f578c334958d
zipfile::decode::unzip permissions bug with some zips
User & Date: umlaeute 2025-03-06 16:40:22
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. comment changed to:
    Some ZIP-files generated on Windows cannot be properly extracted: the extracted files end up with a permission of `0o000`
    
    One such ZIP-file can be downloaded via https://github.com/user-attachments/files/19111907/iem_vanilla.zip
    
    `zipinfo -v` tells me something like this:
    
    ```
    Central directory entry #1:
    ---------------------------
    
      iem_vanilla/0.INTRO.txt
    
      offset of local header from start of archive:   0
                                                      (0000000000000000h) bytes
      file system or operating system of origin:      MS-DOS, OS/2 or NT FAT
      version of encoding software:                   2.0
      minimum file system compatibility required:     MS-DOS, OS/2 or NT FAT
      minimum software version required to extract:   2.0
      compression method:                             deflated
      compression sub-type (deflation):               normal
      file security status:                           not encrypted
      extended local header:                          no
      file last modified on (DOS date/time):          2020 Oct 30 15:42:26
      32-bit CRC value (hex):                         bda8cbfe
      compressed size:                                1861 bytes
      uncompressed size:                              4899 bytes
      length of filename:                             23 characters
      length of extra field:                          0 bytes
      length of file comment:                         0 characters
      disk number on which file begins:               disk 1
      apparent file type:                             text
      non-MSDOS external file attributes:             000000 hex
      MS-DOS file attributes (20 hex):                arc 
    
      There is no file comment.
    ```
    
    The problem is apparently, that the `efattr` field for the file is something like `32`, which tcllib takes as an invitation to change the permissions, but then calculates the permissions as `0`.
    Cf this code for [::zipfile::decode::CopyFile](https://core.tcl-lang.org/tcllib/file?ci=tip&name=modules/zip/decode.tcl&ln=220-234):
    ```
        if {
    	($::tcl_platform(platform) ne "windows") &&
    	($fd(efattr) != 0)
        } {
    	file attributes $dst -permissions \
    	    [string map {0 --- 1 --x 2 -w- 3 -wx 4 r-- 5 r-x 6 rw- 7 rwx} \
    		 [format %03o [expr {($fd(efattr) >> 16) & 0x1ff}]]]
        }
    ```
    
    (obviously, `(32>>16)&0x1ff` evaluates to `0`.
    
  4. foundin changed to: "2.0"
  5. is_private changed to: "0"
  6. login: "umlaeute"
  7. mimetype: "text/x-markdown"
  8. priority changed to: "5 Medium"
  9. private_contact changed to: "25d17d5d6504beca5be732fc23fc1776440fca23"
  10. resolution changed to: "None"
  11. severity changed to: "Minor"
  12. status changed to: "Open"
  13. submitter changed to: "umlaeute"
  14. subsystem changed to: "zip"
  15. title changed to:
    zipfile::decode::unzip permissions bug with some zips
    
  16. type changed to: "Bug"