7
Vote

name clash possible with temporary file during extraction

description

Ok let me try to explain it better.
 
Suppose I have a zip file which contains: helloworld.txt test.txt
 
Now suppose I try to extract this zipfile into a directory, c:\Test . What happens is, for each file in the zipfile the library creates a filename.ext.tmp while he unpacks the specific file of the ze.Extract. That means, when it extracts helloworld.txt on ze.Extract(...); in the folder c:\test\ there will be a file called helloworld.txt.tmp till extract finishes.
 
A problem occurs when C:\test already has a file called helloworld.txt.tmp . If that happens, the library just fails with a message stating that the file already exists (the helloworld.txt.tmp, not the helloworld.txt).

comments

Pointy wrote Aug 16, 2011 at 8:16 AM

The code sample in this work item produces a zip with an invalid CRC:

http://dotnetzip.codeplex.com/workitem/14087

Might help reproduce the *.tmp file issue above.

DexMiK wrote Aug 16, 2011 at 3:27 PM

blake05 wrote Jul 31, 2012 at 7:09 PM

Hello,

I'm also running into this behavior. Are there any plans to update the code for this any time soon? Why not just create a .tmp file in a temp directory...?

aquariusquintini wrote May 2, 2013 at 7:29 PM

Hello,

Same issue here.

I added the following hack/workaround to our code until this issue is fixed in the Ionic library

The hack version:
using (var zipFile = ZipFile.Read(filePath))
{
  foreach (var entry in zipFile.Entries)
  {
    var extractPath = Path.Combine(unzipPath, entry.FileName);
    var extractTmpPath = string.Concat(extractPath, ".tmp");

    // Check if the temp file already exists
    if (File.Exists(extractTmpPath))
    {
      // Remove the temp file
      _Log.Info("Deleting existing temp file ({0}) to prevent problems with extraction.", extractTmpPath);
      File.Delete(extractTmpPath);
    }

    // Extract the actual file from the zip.
    entry.Extract(unzipPath, ExtractExistingFileAction.OverwriteSilently);
  }
}
The original code:
using (var zipFile = ZipFile.Read(filePath))
{
  zipFile.ExtractAll(unzipPath, ExtractExistingFileAction.OverwriteSilently);
}

Serg_G wrote Jan 10 at 11:29 AM

I have faced this issue trying to unpack a lot of items into the one directory parallel. It seems like there was files with one name in some zips. So in spite of ExtractExistingFileAction.OverwriteSilently option the conflict of tmp filenames lead to the exception.