SharpDevelop Community

Get your problems solved!
Welcome to SharpDevelop Community Sign in | Join | Help
in Search

"Zip archive ends early" exception

Last post 05-18-2013 12:42 AM by DavidPierson. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 12-21-2007 9:32 PM

    • peanut
    • Not Ranked
    • Joined on 12-21-2007
    • Posts 1

    "Zip archive ends early" exception

    I found the following issue with SharpZipLib (as well the nightly build

    My situation is that I have a SharpZipLib created ZIP archive that contains a >4GB uncompressed file (and >2GB compressed - this is the important part) along with some other smaller files.  I am able to decompress this with WinZip 9.0 with no problem, but if I even iterate over the ZipEntrys with SharpZipLib 369, it throws a ZipException("Zip archive ends early.") from ZipInputStream.CloseEntry().

    The problem is that the signed 32 bit int 'skipped' local variable is overflowing, and the value goes negative when dealing with > 2^31 byte compressed files.  To workaround this, I just made 'skipped' a long and removed the cast, although I didn't really look at the problem enough to know if this is the best solution.

    Here is a quick test fragment to demonstrate this issue;

    string filename = "";
    Random rand = new Random();

    using(ZipOutputStream zos = new ZipOutputStream(File.Create(filename)))
        long size = 2500000000;

        ZipEntry entry = new ZipEntry("bigfile");
        entry.Size = size;

        long bytesLeft = size;
            int bytesToWrite = (int)(bytesLeft > 65535 ? 65535 : bytesLeft);
            byte[ ] buffer = new byte[bytesToWrite];

            zos.Write(buffer, 0, bytesToWrite);
            bytesLeft -= bytesToWrite;
        while(bytesLeft > 0);

    long uncompressedSize = 0;
    using(ZipInputStream zis = new ZipInputStream(File.OpenRead(filename)))
        ZipEntry entry;
        while((entry = zis.GetNextEntry()) != null)
            uncompressedSize += entry.Size;


  • 12-23-2007 8:52 PM In reply to

    Re: "Zip archive ends early" exception


    Well spotted, the fix is OK I think.


  • 05-15-2013 4:21 PM In reply to

    Re: "Zip archive ends early" exception

    I'm adding this note here in case anyone comes across this while googling the error (this was my first hit when searching for that message).

    Unhandled exception processing "".
    ICSharpCode.SharpZipLib.ZipException: zip archive ends early.
       at ICSharpCode.SharpZipLib.Zip.ZipInputStream.CloseEntry()
       at ICSharpCode.SharpZipLib.Zip.ZipInputStream.GetNextEntry()

    I encountered this same error when trying to read a Zip file created by SharpZipLib 0.86, using a client that had SharpZipLib 0.5.  When I upgraded the client app to have the correct SharpZipLib dll, the problem went away.


  • 05-18-2013 12:42 AM In reply to

    Re: "Zip archive ends early" exception

    Wayne, thanks for the update.

    If you've upgraded to 0.86 you may want to be aware of a change since that old 0.5 version. SharpZipLib handles the Zip64 format now - and I'd reckon it was this format that the old 0.5 was stumbling over.

    If you are using the ZipOutputstream to create, and when adding an entry you do not specify the Size property, the library now plays safe and in case you may be adding content over 4GB, it will default to Zip64 format.The built-in extractor in WinXp and Server2003 does not handle that. WinZip 9 and up does.

    If your files are under 4GB you'd be best to set the ZipEntry.Size if available. Then the format will be chosen correctly.

    Please ignore all this if irrelevant or you already you knew it!


Page 1 of 1 (4 items)
Powered by Community Server (Commercial Edition), by Telligent Systems
Don't contact us via this ( email address.