by GrumpySloth · 5y ago · 0 comments
> This is undefined by the spec.
> There are 2 obvious ways.
> 1. Scan from the front, when you see an id for a record do the appropriate thing.
> 2. Scan from the back, find the end-of-central-directory-record and then use it to read through the central directory, only looking at things the central directory references.
I was recently bitten by this at work. I got a zip from someone and couldn't find inside the files that were supposed to be there. I asked a colleague, and they sent me a screenshot showing that the files were there, and that they didn't see the set of files that I saw. I listed the content of the zip using the "unzip -l" command. They used the engrampa GUI. At that point I looked at the hexdump of the file. What caught my eye was that I saw the zip magic number near the end of the zip, which was odd. The magic number was also present at the beginning of the file. At this point I suspected that someone used cat(1) to concatenate two zips together. I checked it with dd(1), extracting the sequence of bytes before the second occurrence of the zip magic number and the remainder into two separate files. And sure enough at that point both "unzip -l" and "engrampa" showed the same set of files, and both could show both zips correctly. Turns out engrampa was reading the file forwards, whereas unzip was reading the file backwards.
[0]: https://www.lexaloffle.com/pico-8.php
[1]: https://www.lexaloffle.com/bbs/?cat=7&carts_tab=1#sub=2&mode...
> The polyglot file pocorgtfo10.pdf is valid as a PDF, as a ZIP file, and as an LSMV recording of a Tool Assisted Speedrun (TAS) that exploits Pokémon Red in a Super GameBoy on a Super NES. The result of the exploit is a chat room that plays the text of PoCkGTFO 10:3.
You mean like the GIFAR attack (https://en.wikipedia.org/wiki/GIFAR)?
The most iconic /i/ kit spread this way being Dangerous Kitten (https://web.archive.org/web/20120322025258/http://partyvan.i...)
This is also why traditionally zip are read from backwards.
No need to wait. Microsoft does this in their file formats. (E.g., PowerBI's pbix files have this pattern.)
Was the second zip less than 64KB in size? If not then engrampa was being extra wrong about looking for the header.
* Since the signature is put somewhwere between zip headers instead of separate file there needs to be little bit of parsing to locate it and the hash isn't straight forward hash of whole file because it needs to exclude the signature part.
edit: turns out they later also added a version of external signature
Per the blog + spec:
A ZIP file MUST have only one "end of central directory record".