#19 tarvfs bug with "solaris"-tar

closed-fixed
Vince Darley
5
2003-10-30
2003-10-13
Stefan Vogel
No

Sorry to file in a bug for my own code ;-)
I just detected that you can give some nasty "path-
prefixes" to your files inside "tar", e.g when taring like
this:
tar -cf my.tar ./dir1 ./dir2
tarvfs is not able to go into that structure because
those prefixes "./" are stored inside the tar as well.

The fix is in tarvfs.tcl in proc tar::TOC
starting at line 312 the code currently currently looks
like this:
set startPosition [expr $pos+$BLOCK_SIZE]
if {$name != ""} {
incr sb(nitems)
set sb($name,start) [expr $pos+$BLOCK_SIZE]

and should be modified to this:

set startPosition [expr $pos+$BLOCK_SIZE]
# make it relative to this working-directory, remove the
leading "relative"-paths
set name [string trimleft $name "./"]
if {$name != ""} {
incr sb(nitems)
set sb($name,start) [expr $pos+$BLOCK_SIZE]

This removes the relative-paths from the tar, so that
you can walk through the tar-archive as usual.

Thanks
Stefan

Discussion

  • Vince Darley
    Vince Darley
    2003-10-24

    Logged In: YES
    user_id=32170

    The use of 'string trim' is a bit suspect there. How about:

    if {[string range $name 0 1] eq "./"} {
    set name [string range $name 2 end]
    }

    Or, to be even more robust:

    while {[string range $name 0 1] eq "./"} {
    set name [string range $name 2 end]
    }

     
  • Vince Darley
    Vince Darley
    2003-10-24

    • assigned_to: nobody --> vincentdarley
     
  • Stefan Vogel
    Stefan Vogel
    2003-10-30

    Logged In: YES
    user_id=250752

    Hi Vincent,

    you're right. "string trimleft" is even removing the "." in
    e.g. ".bash". The problem is that relative-paths are stored in
    the tar-archive exactly as they were given.
    There are many possibilities to call tar (even if I hope nobody
    does such "strange" things):
    * tar -cf x.tar ../.././../.dir
    * tar -cf x.tar /tmp
    * tar -cf x.tar ./dir

    All those "prefixes" had to be removed because in vfs we
    should start relative to the upper "real"-dir ("dir" or "tmp" in
    the above examples).
    I came about using regexp, that is

    # make it realitive
    regexp -- {^(\.\.?/)*/?(.*)} $name dummy1 dummy2 path

    Best regards
    Stefan

     
  • Vince Darley
    Vince Darley
    2003-10-30

    Logged In: YES
    user_id=32170

    Thanks -- fixed. Please test.

     
  • Vince Darley
    Vince Darley
    2003-10-30

    • status: open --> closed-fixed