name clash possible with temporary file during extraction


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).


Pointy wrote Aug 16, 2011 at 7:16 AM

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


Might help reproduce the *.tmp file issue above.

wrote Aug 16, 2011 at 12:53 PM

DexMiK wrote Aug 16, 2011 at 2:27 PM

wrote Mar 5, 2012 at 11:43 AM

wrote May 29, 2012 at 2:20 PM

blake05 wrote Jul 31, 2012 at 6:09 PM


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...?

wrote Feb 22, 2013 at 1:43 AM

aquariusquintini wrote May 2, 2013 at 6:29 PM


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);

    // 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);

wrote Jul 23, 2013 at 4:37 PM

wrote Sep 24, 2013 at 4:48 PM

wrote Jan 10, 2014 at 10:10 AM

Serg_G wrote Jan 10, 2014 at 10: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.

dwstark wrote Jun 19 at 7:36 PM

The way the code is written, it can completely fail to extract to an empty directory if the zip archive as created contains adjacent files:


The failure occurs if x.txt.tmp is extracted first (not just a hypothetical scenario, hence I am commenting here). Then when x.txt is to be extracted, x.txt.tmp already exists and the code throws on ZipEntry.Extract.cs line 770:
                output = new FileStream(targetFileName, FileMode.CreateNew);
Instead of a simple "add .tmp on the end" to get a temporary file name, something less "Cheesy" is required. (Sorry.)

Seems like the inability to extract files with the above pattern would warrant a higher impact than 'Low'.

dwstark wrote Jun 19 at 8:48 PM

OK. Totally missed that this project moved to github. https://github.com/haf/DotNetZip.Semverd