xxx.zip is not a valid zip file

Apr 3, 2009 at 12:14 AM
Hello,
I'm testing your Ionic.Zip.dll v1.7 in vs2005
I added it to my web app and added a reference to it. Then tested creating a zip file, which worked.
Then I attempted to extract the recently created zip file, and I got an error.

The inner exception message is: "Could not read signature - no data! (position 0x0006A9E4)"
at Ionic.Zip.SharedUtilities._ReadFourBytes(Stream s, String message)
at Ionic.Zip.SharedUtilities.ReadSignature(Stream s)
at Ionic.Zip.SharedUtilities.FindSignature(Stream stream, Int32 SignatureToFind)
at Ionic.Zip.ZipFile.ReadIntoInstance(ZipFile zf)
at Ionic.Zip.ZipFile.Read(String zipFileName, TextWriter statusMessageWriter, Encoding encoding, EventHandler`1 readProgress)

Thanks for your input
Coordinator
Apr 3, 2009 at 12:40 AM
Can you show me the code?
Apr 3, 2009 at 4:55 PM
Yeah. I added compress and extract functions to a .cs file, then called those from a .js file when clicking a "Compress" button and an "Extract" button:

JS CALL:

else if (btnPrs == "TST_COMPRESS")
{
    Ama.Gol.Diagram.DiagramImport.TstZipCompress();
}
else if (btnPrs == "TST_EXTRACT")
{
    Ama.Gol.Diagram.DiagramImport.TstZipExtract();
}

CS f(x)s:

public static void TstZipCompress()
{
    using (ZipFile zip = new ZipFile())
   {
        zip.AddItem(@"C:\Windows\Explorer.exe", @"FileManager\Explorer.exe");
        zip.AddItem(@"C:\Windows\Notepad.exe",@"TextManager\Notepad.exe");
        zip.Comment = "This zip was created at " + System.DateTime.Now.ToString("G");
        zip.Save(@"C:\Temp\Packed.zip");
    }
}

public static void TstZipExtract()
{
    using (ZipFile zip = ZipFile.Read(@"C:\Temp\Packed.zip"))
    {
         foreach (ZipEntry e in zip)
         {
                e.Extract(@"C:\Temp", true);    // overwrite == true
         }
    }
}

Regards

 

Coordinator
Apr 3, 2009 at 6:03 PM
The code looks fine.  Pretty basic. I would expect it to work as you want it to.

what specific version of 1.7 - do you have the latest?
Is this reproducible? Does it happen every time?  Have you ever been able to read or extract a zip file?
how does the javascript call the C#?  
Does it matter what you put into the zip file? What if you added different files instead of explorer and notepad.exe?
Does it happen outside the web app?  If you put the same code in a console app, does the same problem occur?
Apr 3, 2009 at 9:01 PM
Version I used in my web app: v1.7 packed Wed-03-04-2009--00924.41.
First time I attempt to read/extract a zip file. Have been able to compress/extract cab files with another library that did not convince me due to deployment issues.
Javascript instantiated within an aspx page, when clicking a button. C# compiled into a dll in my solution.
I tested with .doc files too. Compression works, extraction fails.

I also tested w/a sample exe that comes in the DotNetZip utilities and tools, for DotNetZip v1.7.  (Packed Wed-03-04-2009--00924.41.).
Placed the unzip.exe and the .dll that came in that zip file, in the same c:\temp where I successfully compressed the files.
Failed to extract both zips, the one with the exe files and the one with the doc files.

Same error message:
C:\Temp>unzip packed.zip -o
exception: Ionic.Zip.ZipException: packed.zip is not a valid zip file ---> Ionic.Zip.BadReadException: Could not read signature - no data!  (position 0x0006A9E4)
   at Ionic.Zip.SharedUtilities._ReadFourBytes(Stream s, String message)
   at Ionic.Zip.SharedUtilities.ReadSignature(Stream s)
   at Ionic.Zip.SharedUtilities.FindSignature(Stream stream, Int32 SignatureToFind)
   at Ionic.Zip.ZipFile.ReadIntoInstance(ZipFile zf)
   at Ionic.Zip.ZipFile.Read(String zipFileName, TextWriter statusMessageWriter, Encoding encoding, EventHandler`1 readProgress)
   --- End of inner exception stack trace ---
   at Ionic.Zip.ZipFile.Read(String zipFileName, TextWriter statusMessageWriter, Encoding encoding, EventHandler`1 readProgress)
   at Ionic.Zip.ZipFile.Read(String zipFileName, TextWriter statusMessageWriter, Encoding encoding)
   at Ionic.Zip.ZipFile.Read(String zipFileName)
   at Ionic.Zip.Examples.UnZip.Main(String[] args)

Regards
Coordinator
Apr 28, 2009 at 6:56 PM
Ok, what I am seeing on this is that normal efforts to unzip a file are failing.
The most likely explanation is that the zipfile is corrupted or not correct.
Can you show me how you created the zip file?
or post the zipfile somewhere?
Apr 29, 2009 at 7:37 AM
i have the same problem

on the production machine all goes ok, on the target machine (windows server 2008) the extraction fail (with the same .zip file).

found the solution! using the release compilation solve the problem!

before i use debug compilation and with this not function on target machine.

hope this help
Coordinator
Apr 29, 2009 at 7:49 PM
newToVs, the problem you reported was due to a bug in DotNetZip.
see http://dotnetzip.codeplex.com/WorkItem/View.aspx?WorkItemId=7711

The workaround is to append four (4) space characters to the end of the zipfile comment.
You can also upgrade to v1.7.2.13 which will avoid the problem.

Fastlink, I am not sure what your problem was/is.  But it seems you addressed it, so I won't worry about it further.
May 8, 2009 at 8:24 PM

Thank you for taking the time to look at this. I have paused my research on file compression/extraction for now -work overload- but will dowload v1.7.2.13 when I continue with it.

Regards