Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: 53f11c6700e7281537b447d5a60a1962d60409062c8b10768c3b7994b08c57af
Ticket: aaa84fbbc59fc039788c080a8cd32d2f73316db9
zipfs info on mountpoint of executable returns zero offset in field 4
User & Date: juliannoble2 on 2024-10-30 03:50:13
Changes

  1. icomment:
    I'll attempt to provide some more context regarding this issue.
    
    The zip archive format (or zip 'container format') is tolerant of 2 ways of prepending data that isn't part of the archive contents as far as what is extracted/listed.
    
    I'll refer to such data - which may be for example a script or an executable (or in less common cases a signature - or other application specific data)
    as the 'preamble'.
    
    This could be an 'external preamble' - e.g as would be created by the method noted in tip 430 by just catting an exe and a zip together.
    
    It could be an 'internal preamble' - which might be created by the same method - but then 'adjusting' the zip offsets such that the preamble is part of the range of data covered by the offsets. e.g using something like 'zip -A' on it.
    
    'zipfs info' can currently only return the offset for the mountpoint as documented in the Tcl zipfs man page if it is an external preamble.
    If adjustments have been made - zipfs info will return zero for the offset.
    
    In some sense this is correct. By making the preamble internal - the zip archive portion does in effect begin at 0 - the start of the whole file.
    That zipfs mkimg - and the build system (using zip -A) create an internal preamble by default is the cause of this.
    
    This default to 'internal preamble' is then at odds with the documentation, and the 'zipfs info' result cannot as claimed be used to 'truncate the zip information from an executable' 
    
    Note that while in nearly every case external zip tools can extract zip contents from a preambled file whether internal or external - there are differences in direct writability etc - and some tools exercise different codepaths based on the file extension.  
    A file that is named with a .zip extension - is generally expected by tools to be an archive with either no preamble, or one that is internal.
    
    pkware are the supposed stewards of the format - having released various appnotes giving a somewhat underspecified documentation of it.
    Although the original author Phil Kats released the format to the public domain - it is unclear to what extent versions documented by pkware after his death contain copyrighted extensions especially related to encryption. This is probably why various other projects that have made use of the zip format have tended to restrict the features used.
    
    pkware put their self extractor exe as an 'internal preamble' - and their tools tend not to support files with arbitrary extensions on the commandline (they assume or require .zip or .exe)
    
    Other tools will generally accept e.g file.kit, file.jar, file.apk etc and list/extract contents 
    
    -----------
    
    Catting a Tcl exe or script preamble to a zip file which already has an internal preamble will result in a file with both an external and internal preamble.
    This has at least one possibly rare legitimate usecase
    There is at least one zip signing tool which uses an internal preamble instead of other mechanisms to store the signature.
    (Other mechanisms include putting it in the comment(seems dubious way to do it) or in the archive itself as for example .jar files do)
    
    Catting for example a tcl executable to an existing sfx would also result in a mixed external/internal preamble. This is another unlikely usecase - in that while the internal sfx header seems to do no harm - its only utility is if the tcl preamble is later split off and the resulting zip is wanted to remain an sfx. Generally its probably just a waste of space.
    
    If a zip kit/exe with both an external and internal preamble is adjusted to make all the preambles internal - there is information loss regarding where the split occurs between the preambles. (Possibly not a case particularly cared about/important in the Tcl zipfs ecosystem but an undocumented edge case nonetheless)
    
    If a tcl exe or script preamble is adjusted to be internal - the split between preamble and zip is also harder to ascertain. It's not an issue for extracting/reading the zip contents - but for determining where the preamble ends.
    (easy enough if you know there is just one script delimited with \x1a - not so easy for cross-platform formats of executables or application specific data etc)
    
    Internal preamble splitting generally relies on using the first file record pointed to by the zip-archives Central Directory.
    1) as a reduced case for just a zip file with no contents but just a comment - there isn't even a CDR (just an end of central directory record)
      (zipfs can't mount an empty zip, vfs::zip can - but in any case read-only - so probably not relevant to Tcl as it stands)
    2) existing zip archives can have either internal preambles, or file records that are unreferenced by the CDR
    
    
    This makes splitting hard. Not an issue just for extracting/reading, or for just running or self extracting - but without a functional 'zipfs info' users have to parse the zip themselves to split the Tcl preamble. Such parsing is tricky/error prone even without unusual cases - and presumably what zipfs info's offset result was supposed to avoid the need for.
    
    Tcl's zipfs can currently split an external preamble no problem and reports it in 'zipfs info'.
    
    To fix 'zipfs info' for the current default of 'internal preamble' - some not completely reliable CDR mechanism will need to be used.
    It could be made 'completely reliable' by documenting the restrictions Tcl places on zip archives (specifically no comment only or empty zips, and all files must be referenced by (and in order) the CDR)
    
    Opinion:  The current default (which I don't believe was the original?) to 'adjusting offsets' and using internal preamble is unnecessary, more complicated, more restrictive.
    (and currently not fully supported as evidenced by 'zipfs info' output)
    
    If the intention is to stick with the default (by zipfs mkimg and build system) internalizing of the Tcl preamble into the zip offset range - a decision needs to be made on what zipfs info reports. While technically correct (there is no offset - it was adjusted away) - it's not useful, and not coherent with documentation.
    
    If sticking with this default - zipfs info should still report the correct offset as it currently does for the simpler and IMO more sensible external Tcl preamble situation.
    
    Regarding use of external zip tools on preambled zips: The situation on windows I believe favours external plain catted preambles for files not named with the .zip extension - but there are many variations in behaviour across platforms and tools. 7zip is available on all platforms and works well with external preambles.
    
  2. login: "juliannoble2"
  3. mimetype: "text/plain"