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 archive.zip
Archive:  archive.zip
warning [archive.zip]:  1520265671 extra bytes at beginning or within zipfile
  (attempting to process anyway)
error [archive.zip]:  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 input.zip --out output.zip

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

$ zip -FF archive.zip --out archive-fixed.zip
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 archive-fixed.zip
Archive:  archive-fixed.zip
 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.