Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  nodelist  faq  login

Kiss your keyboard goodbye!


programming / comp.lang.tcl / Re: tclvfs: vfs::zip discards leading dots in filenames

SubjectAuthor
* tclvfs: vfs::zip discards leading dots in filenamesRalf Fassel
`- Re: tclvfs: vfs::zip discards leading dots in filenamessaitology9

1
Subject: tclvfs: vfs::zip discards leading dots in filenames
From: Ralf Fassel
Newsgroups: comp.lang.tcl
Date: Mon, 9 May 2022 17:06 UTC
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: ralf...@gmx.de (Ralf Fassel)
Newsgroups: comp.lang.tcl
Subject: tclvfs: vfs::zip discards leading dots in filenames
Date: Mon, 09 May 2022 19:06:01 +0200
Lines: 72
Message-ID: <yga1qx2tz46.fsf@akutech.de>
Mime-Version: 1.0
Content-Type: text/plain
X-Trace: individual.net Mr/TAtU4c+q6FeP4GDQiQw0HPpxfePAaMWC2ArZ/L7Uf3KNig=
Cancel-Lock: sha1:qWdW3V8UfbT0A3DiWH4MA0cAET8= sha1:/Z+LEzA0CPvdju3uVb1bnoZx7/k=
User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.3 (gnu/linux)
View all headers
Ticket:
https://core.tcl-lang.org/tclvfs/tktview/887778e1916c934f8a303a6337a10869d0ac2963

tcl 8.6.12

tclvfs module vfs::zip discards the leading dot of files stored in an
ZIP archive:

    # create ZIP archive
    $ touch .foo bar
    $ zip test.zip .foo bar

open via vfs::zip

    $ tclsh
    % package require vfs::zip
    1.0.4
    % vfs::zip::Mount test.zip test.zip
    file3
    % glob test.zip/*
    test.zip/bar test.zip/foo

As you can see, '.foo' became 'foo' in vfs::zip

    % open test.zip/bar
    rc0
    % open test.zip/.foo
    couldn't open "test.zip/.foo": no such file or directory
    % open test.zip/foo
    rc1

But the ZIP really holds '.foo', not 'foo'

    % exec unzip -l test.zip
    Archive:  test.zip
      Length      Date    Time    Name
    ---------  ---------- -----   ----
            0  2022-05-09 18:15   .foo
            0  2022-05-09 18:15   bar
    ---------                     -------
            0                     2 files


This is due to the following code in

    proc zip::TOC {...} {
      ...
      set sb(name) [string trimleft $sb(name) "./"]

which looks suspiciously like someone was trying to strip off the "./"
prefix sequence from names like "./foo"

Cleary stripping off the dot from a file name is plain wrong.

Proposed patch

    --- zipvfs.tcl 2022/05/09 17:00:22 1.1
    +++ zipvfs.tcl 2022/05/09 17:00:28
    @@ -546,7 +546,9 @@
             set sb(name) [encoding convertfrom utf-8 $sb(name)]
             set sb(comment) [encoding convertfrom utf-8 $sb(comment)]
         }
    -    set sb(name) [string trimleft $sb(name) "./"]
    +    if {[string range $sb(name) 0 1] == "./"} {
    + set sb(name) [string range $sb(name) 2 end]
    +    }
         set parent [file dirname $sb(name)]
         if {$parent == "."} {set parent ""}
         lappend cbdir([string tolower $parent]) [file tail [string trimright $sb(name) /]]


R'


Subject: Re: tclvfs: vfs::zip discards leading dots in filenames
From: saitolo...@gmail.com
Newsgroups: comp.lang.tcl
Organization: Aioe.org NNTP Server
Date: Mon, 9 May 2022 18:05 UTC
References: 1
Path: i2pn2.org!i2pn.org!aioe.org!a5rWVvs5S5ZXUwkNcVnRMw.user.46.165.242.91.POSTED!not-for-mail
From: saitolo...@gmail.com
Newsgroups: comp.lang.tcl
Subject: Re: tclvfs: vfs::zip discards leading dots in filenames
Date: Mon, 9 May 2022 14:05:13 -0400
Organization: Aioe.org NNTP Server
Message-ID: <t5bl4t$1hh7$1@gioia.aioe.org>
References: <yga1qx2tz46.fsf@akutech.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Info: gioia.aioe.org; logging-data="50727"; posting-host="a5rWVvs5S5ZXUwkNcVnRMw.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.6.1
X-Notice: Filtered by postfilter v. 0.9.2
Content-Language: en-US
View all headers
On 5/9/22 1:06 PM, Ralf Fassel wrote:

This is due to the following code in

     proc zip::TOC {...} {
       ...
       set sb(name) [string trimleft $sb(name) "./"]

which looks suspiciously like someone was trying to strip off the "./"
prefix sequence from names like "./foo"

Cleary stripping off the dot from a file name is plain wrong.



Hello,

You are correct.  "./" prefix in a file name resolves to the file name itself: the "." means in the current directory, and the slash is the usual file separator.

However, it looks like a bug, to be honest.  The command "string trimleft" will trim *any* characters in its second argument.  I suspect the error is that the sequencing of those characters matters, which in reality,  does not.  There are several file commands to deal with such cases.



1
rocksolid light 0.7.2
clearneti2ptor