1
Vote

ExtractFile method does not report error for password protected archive files accurately

description

When extracting files from a password protected archive file (e.g. zip), ExtractFile method will not throw an error stating that the archive file is password protected, it extracts a file (incorrectly since no password was provided) then will throw an exception stating the file may be corrupt or that the crc check failed on the extracted file. The real problem is that the archive is password protected but no password was provided during extraction.
 
Code sample below:
 
using (SevenZipExtractor extractor = new SevenZipExtractor(File.OpenRead(_path)))
{
OnFeedback(new MessageEventArgs("Unpacking " + _path)); 
for (int i = 0; i < extractor.FilesCount; i++)
{
    if (CancelFlag)
    {
        OnError(new MessageEventArgs("Unpacking cancelled"));
        return false;
    }
    string fileName = extractor.ArchiveFileNames[i];
    string unpackLocation = GetTempFileName() + Utilities.PathUtility.GetExtension(fileName);
 
    UnpackFile unpackFile = new UnpackFile()
        {
            FileLocation = unpackLocation,
            InternalFileName = Path.GetFileName(fileName),
            InternalPath = Convert.ToString(Utilities.PathUtility.RootPath(fileName)),
            Extension = Path.GetExtension(fileName),
            FileInfo = new Dictionary<string, string>()
        };
    var stream = File.Open(unpackLocation, FileMode.CreateNew, FileAccess.Write);

    extractor.ExtractFile(i, stream);

    stream.Close();
 
}
}
 
I am using 0.64.3890.29348 sevenzipsharp.dll.

comments