This project is read-only.

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 8: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 1:53 PM

DexMiK wrote Aug 16, 2011 at 3:27 PM

wrote Mar 5, 2012 at 12:43 PM

wrote May 29, 2012 at 3:20 PM

blake05 wrote Jul 31, 2012 at 7: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 2:43 AM

aquariusquintini wrote May 2, 2013 at 7: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 5:37 PM

wrote Sep 24, 2013 at 5:48 PM

wrote Jan 10, 2014 at 11:10 AM

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

dwstark wrote Jun 19, 2017 at 8: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, 2017 at 9:48 PM

OK. Totally missed that this project moved to github.