Re:JPEG image of Shakespeare which is also a zip file contai...
by plaguuuuuu on Tuesday October 30, 2018 @11:02PM
(#18343033)
I can't exactly remember what JPG and ZIP look like, but yeah pretty much, I've done it before.
What's surprising is that it works on Twitter. I tried the same thing with image hosts and the data got scrubbed. I guess they don't re-encode small images but I dunno.
Basically the "top level" zip file section lives at the end of the zip file and contains pointers back into the file for the actual data. This is so that you can keep adding to a zip file without having to rewrite anything you have done previously - just append a few more files and then your updated directory at the end.
JPEG segments contain two special opening bytes, maybe a length, and then the actual data. So it would be trivial to have the last jpeg section in a jpeg file end with zip directory bytes. This directory could point back to data in other sections of the jpeg.
..my guess, anyway.