Skip to content
Tcl Source Code View Ticket
Login

View Ticket

2024-10-12
14:59 • Ticket [26547532af] zipfs offsets are a problem status still Open with 4 oth... artifact: 22164d8d6c user: juliannoble2
2024-10-11
06:37 • New ticket [26547532af]. artifact: 7166783266 user: juliannoble2

zipfs offsets are a problem

Open26547532af7fb7d24b2cd101b85abdb1a1af6291Created 2 years agoUpdated 2 years ago
Descriptionplain2024-10-11 06:37:49
It's long established in the windows world at least that executables can be joined to the beginning of a zipfile by simple catenation.

  cat some.exe some.zip > exewithzip.exe

Various programs use this.. e.g just a random example: https://jasonliang.js.org/fusing.html
 but it shows an equivalent method: 
  copy /b input.exe+input.zip exewithzip.exe

These exewithzip.exe files can be easily updated either on commandline or through the graphical interface with common tools such as 7-zip and PeaZip.

On the other hand files with executables that have been made by the current implementation of zipfs mkimg - or info-zip's 'zip -A' option cannot be updated either graphically or on the commandline with such tools.

Worse - info-zips 'zip -A cattedzip.exe' refused to adjust the offsets anyway when I tried it on windows and suggests trying -FF - which is a terrible idea because it just produces a zip with the exe part stripped off.

As venerable and widespread as info-zip is - there are multiple versions with slightly different behaviour and the project seems to be slow to release (glass houses.. but anyway)

As poorly specified as the zip format is - I don't see any justification for info-zips choice to treat offset from the beginning of the file as preferential vs offsets from where the zip archive starts in the file.
The pkware appnotes just say:
"Offset of the start of the central directory on the
      disk on which the central directory starts."

Which is a reference to the old practice of splitting zips across floppies - but says nothing about adjusting offsets for prefix data.

I think info-zips choice and lack of interoperability flies in the face of common practice. (one I believe recognized by pkware but not really clarified)

Tools like 7z are aware of exezips with prefixed data and report it in an unalarming way as:
Offset = xxxx

or.. for an 'adjusted' file produced by zipfs mkzip or zip -A
Embedded Stub Size = xxxx

It can be argued that their choice to cowardly refuse to update a file with un-headered data *within* the range pointed to by the offset is just a different and opposite choice to info-zip's - but I'd argue that info-zip's choice is more cowardly in that the data is clearly separate and a *common* case - and 7z,peazip is just conservative about not breaking something that isn't well understood. 

zip files are scanned by looking for the end of central directory record from the back - and the offsets can be processed from there. No requirement that the offset must be relative to the start of the file is established and I don't think we should reinforce info-zip's take on it.


info-zip's unzip utility chooses not to display the Embedded Stub size on such a file - treating that as somehow 'normal' (it's not disallowed - but there's no justification for treating it as the preferred way)

.. but it chooses to display an offset relative to the start of the zip-portion in an 'alarming' manner:
warning [catted_only.exe]:  xxxx extra bytes at beginning or within zipfile
(attempting to process anyway)


My case is that we shouldn't let info-zip's choices drive the decision - and that preserving interoperability of plain catted prefix (whether it be a tcl script + ctrl-z + zip or exe + zip) is more important.

7z is available on windows,BSDs,linux and I believe also Macs.

unzipping catted exezips doesn't seem to be a problem with the tools I tested either 'adjusted' or not.

My patch attached to ticket: https://core.tcl-lang.org/tcl/tktview/ad7bafd5e1 (though not really the right place for the core topic of that ticket)  works for me on windows but I would like to hear arguments about why the offset adjustments are being made.

ticket: https://core.tcl-lang.org/tcl/tktview/fc65ff1b663fd16e7582  is where the adjustments were changed from being relative to the zip-archive start to relative to the file start.
The way we used to have them (relative to archive start) is I think the better way.
The issue in that ticket was about 'zipfs mkimg' failing to output the executable part at all under linux static builds - but whatever caused that should be independent of how the offsets are written.
juliannoble2plain2024-10-12 14:59:02
This late in the process (post release Tcl9) I don't genuinely expect there is a high likelihood the project will move in this direction.

I request that if possible this be left as a request for enhancement (long term - details below) and effectively at least stand as note that usability of zip-enhanced exes and kits can potentially vacillate between two states depending on how offsets are calculated.

That either is generally readable/extractable by tools and zipfs itself is a saving grace.

I note also that having tried only a couple of open source zip signing methods - one was pretty compatible with having a prefix exe/script and could still be run after signing; another rust based one put in it's own prefix and seems completely incompatible. I suspect other signing mechanisms not specific to zip might be the better approach.

For my own purposes I'll likely use/generate kits that are equivalent to concatenated exe/script and zip. (ie unadjusted offsets)
I think a supplementary tool that can convert to either state might also be something I'll work on. (e.g some equivalences to the SDX.kit with things like an easy way to 'split' the zip vs the exe/script - even if offsets have been adjusted one way or the other)

For the long term - I think the zip container 'standard' is so loose and variably interpreted, that the request for enhancement is to look to the future possibility of some other container format - such as that used by 7zip with LZMA etc. Given the amount of hard work everyone put into zipfs and our current small programmer base I expect this is a very long term project.

My understanding is that the 7z format itself should be free to use - but the practicality of this probably depends on availability of BSD/MIT licensed code.

I'll add that despite my apparent frustration here - that's more about the realities of the zip container format - and I really do appreciate the great work and the big step forward that this is for Tcl.
Log in (anonymous is fine) to add a comment.