Rename zipentry results in bad zip (ZIP64)

Mar 3, 2009 at 12:28 PM
Hi Folks,

I have noticed that when you rename one or more files in a large (ZIP64) zip file, the zip file becomes unreadable and reports: expected central file header signature not found. When you rename all the files there seems to be no problem.
I am working with zip files that have around 250.000 files in them and are about 1Gb in size.

Some example code (this one works.. set a break in the for lus and break out to see the difference):

Dim

zip As ZipFile

 

 

zip = ZipFile.Read("2005-01.zip")

 

 

For Each file As ZipEntry In zip

 

    file.FileName = file.FileName.Substring(0, 8) +

"abc.pdf"

 

 

Next

 

zip.UseZip64WhenSaving = Zip64Option.AsNecessary

zip.Save()

Coordinator
Mar 3, 2009 at 2:53 PM
Edited Mar 3, 2009 at 3:40 PM
jvkaam, I can see you're having a problem, but I don't understand exactly what it is, or how it is caused.
You'll need to be more specific.

1. What version of the library are you using?  Four-digit version please?
2. When you say "the file becomes unreadable" - what do you mean?  How do you know it has "become unreadable"?   What are you trying to do that does not work, and how does it "not work"?  How are you attempting to read the file?  What have you done before trying to read the zip file?  Have you modified it and saved it?  And then you are trying to read it in another process?    How did you generate the zip file originally?   I need some additional information.
3. I don't understand what you mean by "Set a break in the for lus... to see the difference."    can you specifically describe what your code does when things work correctly, and what your code does when things don't work correctly?

edit:
(ps: I am testing right now with removing an entry from an archive that uses ZIP64)
Coordinator
Mar 3, 2009 at 3:53 PM
I just tried this code here.  It creates a zip file using ZIP64.  Then it reads that ZIP64 file, removes a few entries, and re-saves the file.  Then it reads the zip file again.  It all works.  Does this not work on your system?

    String archiveName = "jvkaam.zip";
    String NameOfDirectoryToZip = "C:\\dinoch\\dev\\dotnet\\zip\\test\\fodder";

    if (System.IO.File.Exists(archiveName))
    {
        Console.WriteLine("Deleting existing archive {0}... ", archiveName);
        System.IO.File.Delete(archiveName);
    }

    Console.WriteLine("============================================");
    Console.WriteLine("Creating archive {0}... ", archiveName);
    using (ZipFile zip = new ZipFile())
    {
        zip.StatusMessageTextWriter = System.Console.Out;
        zip.UseZip64WhenSaving = Zip64Option.Always;
        zip.AddItem(NameOfDirectoryToZip);  // recurse        zip.Save(archiveName);
    }

    Console.WriteLine("============================================");
    Console.WriteLine("The archive has been saved. Now reading it... ");
    using (ZipFile zip = ZipFile.Read(archiveName))
    {
        zip.UseZip64WhenSaving = Zip64Option.Always;
        zip.StatusMessageTextWriter = System.Console.Out;
        var doomed = new System.Collections.Generic.List<ZipEntry> ();
        // remove all .cs files
        foreach (ZipEntry e in zip)
        {
            if (e.FileName.EndsWith(".cs"))
            {
                Console.WriteLine("Marking entry for removal ({0})... ", e.FileName);
                doomed.Add(e);
            }
        }

        Console.WriteLine("Removing {0} entries... ", doomed.Count);
        foreach (ZipEntry e in doomed)
            zip.RemoveEntry(e);  // remove the entry
        Console.WriteLine("Re-saving the archive... ");
        zip.Save(); 
    }

    Console.WriteLine("============================================");
    Console.WriteLine("Now reading again... ");
    using (ZipFile zip = ZipFile.Read(archiveName))
    {
        zip.StatusMessageTextWriter = System.Console.Out;
        Console.WriteLine("listing the entries... ");
        foreach (ZipEntry e in zip)
            Console.WriteLine(" {0}", e.FileName);

    }

Coordinator
Mar 3, 2009 at 7:15 PM
ps; that test used v1.8.1.3 of the DotNetZip libary. 
I don't have a zip file with 200,000 entries, so this does not mirror your situation.  But it would help me if you could share a similar bit of code that reproduces the problem you are seeing.
Mar 3, 2009 at 8:30 PM
Hi Cheeso, Thanx for the quick reply. Let me try to provide some more info. I am working with the Ionic.Zip.Reduced.dll version: 1.7.2.11.
The code to reproduce the problem is exactly as stated above .. very simple:

I open the ZipFile

Dim zip as ZipFile
zip = ZipFile.read("2005-01.zip")

Then I loop through all the files in the Zip with:

for each file as ZipEntry in zip
   'I rename the file
   file.filename = file.filename.substring(0,8) + "aaa.pdf"
next
'and eventually save it
zip.UseZip64WhenSaving = Zip64Option.AsNecessary
zip.save

When I use this code all is fine. I assume that's because all filenames are changed. However when you do something like the following:

dim i as integer
for each file as ZipEntry in zip
   i += 1
  if i > 3 then exit for
  file.filename = file.filename.substring(0,8) + "aaa.pdf"
next

(Yes I know this no elegant code but it will hopefully show what I mean)
So the point is not to change all the filenames but 1 or 2 or untill zip.count-1.
After doing this.. saving and opening the file again with Winzip or so it will report: 'expected central file header signature not found'. I could not reproduce this behavior with small zip files so I gues it has something to do with ZIP64.

Regards,

John

Coordinator
Mar 4, 2009 at 7:00 AM
Ah, yes.  I discovered a problem with ZIP64 that came up when updating zip archives.
The library was not handling that situation properly.
Sorry about the trouble.

I think I've fixed it, but the fixes are available only in v1.8.  Can you check to see if it works for you?
Coordinator
Mar 4, 2009 at 8:25 AM
OK, v1.7.2.12 includes the fix.  It's available now.
I'd like you to try it out, or the v1.8 version.  Or both if you like.

Let me know!
Mar 4, 2009 at 4:28 PM
Hi Cheeso,

Downloaded both versions (1.7.2.12 and 1.8) and the problem is SOLVED! Great job.
Jee you are fast.

Kind regards,

John