Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Correcting Corrupt ZIP file Headers

Tags:

.net

binary

zip

I have previously been using Chilkat Zip .Net to generate backup files from my application, but after having issues with the Component, moved to Xceed Zip .Net for the same function.

If you take one of the Zips generated with the Chilkat and attempt to extract using Xceed, 7Zip, WinZip then it fails.

If you take the same file and extract with Chilkat, Windows Zip, WinRar then the file extracts just fine.

Having a read on Wikipedia about the WinZip format I investigated the Central Directory and the Local File header, and it appears that the Chilkat component has written the Central Directory record filesize incorrectly. If you use something like FRHed to edit the Central Record and make the filesize the same as the Local Header size, then everything extracts correctly.

What would you recommend I do?

  1. Write a small utility using the Chilkat library to extract the Zip and then recompress with the Xceed Library
  2. Read the Zip file looking for the Necessary Zip Markers (as defined in the Spec) and then correct the Central Header.
  3. Some other combination.
like image 595
Paul Farry Avatar asked Aug 16 '10 01:08

Paul Farry


People also ask

Can you fix a corrupt zip file?

Step 1 Launch File Repair Tool and select the "Repair ZIP File" option start to repairing the process. Step 2 Search corrupt ZIP file in local drive and select the specific corrupt ZIP files. Step 3 All corrupt ZIP files list in the result section and click the "Repair" button.

What causes a zip file to be corrupt?

There are various reasons for a zip file corruption. Incomplete download of a zip file from a website, viruses, file system errors, removable media corruption are some of the causes of zip corruption.


1 Answers

It depends on number of backups your program generated. Probably, it would be easier to decompress/recompress them from program or by hands. However, if there is a lot of files, the better way would be to fix central directory record fields - you should write code, which 1) searches for central directory; 2) for each record, goes to position where local file header is stored, and read file size; 3) go back to central directory and write valid file size there; 4) Beware of large files, if they are - file size for files >4Gb is written in extension.

like image 142
Nickolay Olshevsky Avatar answered Sep 22 '22 10:09

Nickolay Olshevsky