Advanced handling of wrong CRC in zip

I am using Aspose Java Zip to unzip a zip file “wrongCRC.zip”.

Correctly, the library complains that the CRC is wrong.

What I would like to have is:

  1. to be able to still access the (probably corrupted) file bytes even if the CRC doesn’t check
  2. to be able to access the other files, in case only one file has the wrong CRC

How could I do it?

Thanks in advance

Hello @mrossi,

I suppose the best option would be to introduce a flag VerifyChecksum (or SkipChecksumCheck) within ArchiveLoadOptions class. Default value will be true, but you can load your archive with intentional skip of CRC verification. However, if algorithm fails to extract due to data corruption you’ll get another exception. Here is the usage scenario in .NET:

using (var archive = new Archive(fs, new ArchiveLoadOptions() { VerifyChecksum = false }))
{
    using (Stream decompressed = archive.Entries[0].Open())
    {
        byte[] buffer = new byte[4096];
        int bytesRead;
        while ((bytesRead = decompressed.Read(buffer, 0, buffer.Length)) > 0)
        {
            destination.Write(buffer, 0, bytesRead);
        }
    }
}

What do you think on such an approach?

  1. Entries are being extracted independently from each other. Above is the sample of extracting a single entry.

I think it’s good. The only thing is that I would make that option similar to the password, so I can pass it as you did in the general ArchiveLoadOptions, but I could also “overwrite it” when opening a single file, to make it more granular

Unlikely we’ll provide such a granularity. There is Extract method with two arguments, expand it with one more even optional argument is too much.
However it is feasible to provide an event OnChecksumVerificationFailed or similar. This event, if agreed, is not for the upcoming version.

Ok, thank you

The property SkipChecksumVerification has introduced in February version of Aspose.ZIP for .NET. Soon you’ll get it for Java version too.