This project is read-only.
3
Vote

AddEntry() deadlock depending on size

description

ZipFile.Save() hangs when 2 files with a size of 65536 * (9 or grater) are added before.
To work around this you have disable compression.
Sample:
    static void Main(string[] args) {

        var zipFile = new Ionic.Zip.ZipFile();
        int contentSize = 65536 * 9; // * 9, 10, 11 ...

        var content1 = new byte[contentSize];
        var content2 = new byte[contentSize];

        zipFile.AddEntry("content1", content1);
        zipFile.AddEntry("content2", content2);

        zipFile.Save(System.IO.Path.GetTempFileName()); // it hangs here

        System.IO.File.Delete(zipFile.Name);
    }

comments

paulzyto wrote Dec 12, 2012 at 7:00 PM

I wrote simple test that demonstrates this problem with a single file. The code creates a random file of a given size and then zip it and unzip it. If there is an error it returns false. I found that most but not all files that are of size that is a multiple of 65536 will fail starting with 65536 * 9. Please fix this bug. I am using version 1.9.1.8.
class Program
{
    static void Main(string[] args)
    {
        if (Directory.Exists(unzipDir))
            Directory.Delete(unzipDir, true);

        Directory.CreateDirectory(unzipDir);

        //6094848
        for (int i = 1; i <= 200; i++)
        {
            int size = 65536 * i;
            if (TestZip(size) == false)
            {
                Console.WriteLine("***" + i.ToString() + " " + size.ToString() + "***");
            }
            else
            {
                Console.WriteLine("..." + i.ToString() + " " + size.ToString() + "...");

            }
        }


        Console.ReadKey();


    }

    private static string unzipDir = @"c:\ziptest\unzipdir";

    private static bool TestZip(int size)
    {
        try
        {
            string filePath = @"c:\ziptest\" + size.ToString();
            string filePathZip = @"c:\ziptest\" + size.ToString()+".zip";
            string filePathUnZip = unzipDir+"\\" + size.ToString();


            byte[] array = new byte[size];
            Random random = new Random();
            random.NextBytes(array);

            if (File.Exists(filePath))
                File.Delete(filePath);

            File.WriteAllBytes(filePath, array);


            if (File.Exists(filePathZip))
                File.Delete(filePathZip);

            Ionic.Zip.ZipFile ZF = new Ionic.Zip.ZipFile();
            ZF.CompressionLevel = Ionic.Zlib.CompressionLevel.BestCompression;
            ZF.AddFile(filePath, "");
            ZF.Save(filePathZip);




            using (ZipFile zip1 = ZipFile.Read(filePathZip))
            {

                if (zip1.Count != 1)
                    throw new Exception("must contain only one file");

                ZipEntry ZE = zip1[0];
                ZE.Extract(unzipDir, ExtractExistingFileAction.OverwriteSilently);
            }


            if (File.Exists(filePath))
                File.Delete(filePath);

            if (File.Exists(filePathZip))
                File.Delete(filePathZip);

            if (File.Exists(filePathUnZip))
                File.Delete(filePathUnZip);


            return true;
        }
        catch
        {
            return false;
        }
    }
}

wrote Dec 27, 2012 at 9:59 PM

keydon wrote Feb 14, 2013 at 3:38 PM

I have the exact same Issue, also same Version.
Please fix that :)

wrote Feb 14, 2013 at 3:45 PM

wrote Feb 14, 2013 at 3:45 PM

wrote Feb 14, 2013 at 3:45 PM

wrote Feb 22, 2013 at 2:42 AM

UrfanD wrote Aug 26, 2016 at 3:41 PM

Hi
Glad I looked at this, I have the same issue. Lots of files (which is fine, unless) some are large
the .Save(..) hangs

I re-did the test and turned compression OFF then re-tested as OK

Iam working on version 1.9.1.8 of Ionic.Zip.DLL

The issue seems to date back awhile to 2012 and its now August 2016
No progress?