Don't zip a file from a subdirectory
10 Jan 2024
So today was a fun day at my university. I got the results back for my term project, and they were lower than I expected. When I made an inquiry into how my project was graded, I was told I didn't submit the source code in the zip file I submitted to the system.
I was confused because I was certain that I did. I downloaded the file onto my Android phone and opened it, and sure enough, the source code and another pdf file were in there. It looked like this:
I showed this to the TA, and he went to try to download the file again on his computer. He downloaded the file on Windows, and when he opened it, only a single pdf file (the final report) was extracted. I was suspecting it was due to some sort of Unix/Windows incompatibility, but he also tried it on an app on his iPad, with the same result.
At this point, I was suspicious of the system used for submissions. I opened my MacBook to try to unzip the file, double-clicked on it in Finder, and... the same thing happened!
Wondering if the zip file was corrupted, I used unzip -t
to test the file. It was fine apparently.
Then I tried just unzipping the file using unzip
. Heureka! The following warnings were printed:
When you give the path of the file to zip, it will be zipped using the path relative to the current directory. Turns out, this also applies to parent directories. While these are ignored when extracting files using the unzip utility, it appears the default desktop archive extractors on macOS and Windows silently fail instead.
1. Create a directory structure like the following:
final/
directory
I tried to send the initial zip file to the TA using my university email, but it was not delivered. Then I tried Gmail on my phone, but the email failed to even be sent. Here is the error when I attempted to send it from my laptop:
I'm not currently sure why Google flags zip files with this characteristic, but since different zip extractors handle the zip file differently, perhaps there is or was some way to exploit this behavior for malicious purposes.
TL;DR: I zipped the files for my term project using the relative path from the subdirectory I was in, which caused the files from parent directories that were added to the archive to be silently ignored when unzipping.