Fix Corrupted Zip Archive

How to fix corrupted zip file using CLI tool

When you download a zip file from the internet, there is a chance that you get a corrupted file. This is not the network fault. The uploader probably doesn’t verify the archive correctly.

Here is an example output when I try to unzip a corrupted zip I get from the internet.

$ unzip
warning []:  1520265671 extra bytes at beginning or within zipfile
  (attempting to process anyway)
error []:  start of central directory not found;
  zipfile corrupt.
  (please check that you have transferred or created the zipfile in the
  appropriate BINARY mode and that you have compiled UnZip properly)

Worry not, the zip command can be used to fix the archive. It’ll try to recover the files as much as possible and put them into a new zip file. The syntax looks like the following snippet.

zip -FF --out

Here is an example output when I try to fix my corrupted zip file.

$ zip -FF --out
Fix archive (-FF) - salvage what can
 Found end record (EOCDR) - says expect single disk archive
Scanning for entries...
 copying: some-file.dat  (xxxxxxx bytes)
Central Directory found...
Zip64 EOCDR found ( 1 5815375365)...
Zip64 EOCDL found ( 1 5815375421)...
EOCDR found ( 1 5815375441)...

After the previous process finished, you can just unzip the newly created zip archive.

$ unzip
 extracting: some-file.dat

That’s it. Now you can get the content from that corrupted zip file.

Hope this simple trick useful for you! Thank you for reading.