zip icon indicating copy to clipboard operation
zip copied to clipboard

Extraction from ZIP archive with prepended data fails

Open monofon opened this issue 6 years ago • 4 comments

I am trying to use this zip implementation to distribute resource data as part of a fat executable, because it is cross platform and has no external dependencies.

Packing and appending the ZIP archive to the executable from Setup.hs works great, however unpacking the data at runtime from Main.hs fails with:

Parsing of archive structure failed:
Cannot locate end of central directory
in ".stack-work/install/x86_64-osx/lts-11.6/8.2.2/bin/self-extracting-zip"

However, unzip reports:

% unzip -l .stack-work/install/x86_64-osx/lts-11.6/8.2.2/bin/self-extracting-zip 
Archive:  .stack-work/install/x86_64-osx/lts-11.6/8.2.2/bin/self-extracting-zip
warning [.stack-work/install/x86_64-osx/lts-11.6/8.2.2/bin/self-extracting-zip]:  2566816 extra bytes at beginning or within zipfile
  (attempting to process anyway)
  Length      Date    Time    Name
---------  ---------- -----   ----
      220  05-20-2018 13:49   app/Main.hs
---------                     -------
      220                     1 file

The entire test project can be found here. My question is, am I doing something wrong, or is this not a valid use case for the library?

Any help will be greatly appreciated.

monofon avatar May 21 '18 09:05 monofon

I'll take a look. Probably this weekend. I'm quite busy these days so I can't assist immediately.

mrkkrp avatar May 21 '18 10:05 mrkkrp

This usage is not supported right now. Zip uses offsets to specify start of file headers, and when you prepend something to zip archive these are no longer valid. unzip probably just knows how to detect size of data at the beginning and adjust the offsets automatically.

We can do it too, just need to sit down and implement. Not sure when I'll have time.

mrkkrp avatar May 23 '18 16:05 mrkkrp

Do you want to prepare a PR? That would be the fastest way forward.

mrkkrp avatar May 24 '18 16:05 mrkkrp

I will see what I can do.

monofon avatar May 25 '18 04:05 monofon