Fix Corrupted Zip Archive

How to fix a corrupted ZIP file using CLI tools

When you download a ZIP file from the internet, there is a chance that you may end up with a corrupted file. This is not necessarily a network issue. The uploader may not have verified the archive correctly.

Here is an example output when trying to unzip a corrupted ZIP file downloaded 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)

Don’t worry—the zip command can be used to repair the archive. It will attempt to recover as much data as possible and write it to a new ZIP file. The syntax looks like this:

zip -FF input.zip --out output.zip

Here is an example output when fixing a 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 process finishes, you can unzip the newly created archive as usual.

$ unzip archive-fixed.zip
Archive:  archive-fixed.zip
 extracting: some-file.dat
 ...
 ...

That’s it. You should now be able to recover the contents of the corrupted ZIP file.

I hope this simple trick is useful for you! Thank you for reading.