SharpDevelop Community

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

Use ZipFile to decompress a largefile throw wrong local header

Last post 11-21-2013 2:41 AM by airwolf2026. 7 replies.
Page 1 of 1 (8 items)
Sort Posts: Previous Next
  • 11-18-2013 3:58 AM

    Use ZipFile to decompress a largefile throw wrong local header

    I had a large zip file (the filesize>4GB),when use zipFile class to extract a file ,the code throw a exception "wrong local header"

     using (ZipFile zf = new ZipFile(path))

                    {

                        foreach (ZipEntry ze in zf)

                        {

                            if (ze.IsFile)

                            {

                                MemoryStream ms = new MemoryStream();

                                using (Stream zis = zf.GetInputStream(ze.ZipFileIndex))

                                {

                                    int size = 2048;

                                    byte[ data = new byte[size];

                                    while (true)

                                    {

                                        size = zis.Read(data, 0, data.Length);

                                        if (size > 0)

                                        {

                                          ms.Write(data, 0, size);

                                            if (ms.Length > ze.Size)

                                                break;

                                        }

                                        else

                                        {

                                            break;

                                        }

                                    }

                                }

    above code work error, but when i use ZipInputStream to extract a file ,it work fine.

      ZipEntry theEntry;

                int size;

                using (ZipInputStream s = new ZipInputStream(File.OpenRead(path)))

                {

                    while ((theEntry = s.GetNextEntry()) != null)

                    {

                        if(theEntry.IsFile)

                        {

                            MemoryStream ms = new MemoryStream();

                            byte[ data = new byte[20480];

                            while (true)

                            {

                                size = s.Read(data, 0, data.Length);

                                if (size > 0)

                                {

                                    ms.Write(data, 0, size);

                                }

                                else

                                {

                                    break;

                                }

                            }

                            ms.Seek(0, SeekOrigin.Begin);

                            break;

                        }

                    }

                }

     

    is there a solution to fix this ,i want to use zipfile class feature?the dll version is 0.86.0.518;

    thanks.

    Filed under:
  • 11-18-2013 4:25 AM In reply to

    Re: Use ZipFile to decompress a largefile throw wrong local header

    Hi,

    In your code, the lines

    if (ms.Length > ze.Size)
           break;

    are unnecessary so please remove them.

    Other than that, the code looks fine, so there must be something wrong in the zip file. Where did it come from?

    Thanks,
    David

  • 11-18-2013 4:27 AM In reply to

    Re: Use ZipFile to decompress a largefile throw wrong local header

    Just spotted something else

     

        using (Stream zis = zf.GetInputStream(ze.ZipFileIndex))

     

    please change to

         using (Stream zis = zf.GetInputStream(ze))

    which is the standard usage.

    Thanks, David

  • 11-18-2013 9:21 AM In reply to

    Re: Use ZipFile to decompress a largefile throw wrong local header

    Hi,

    David, thanks for your reply.

    i) I has change my code using(Stream zis =zf.GetInputStream(ze)),i know the difference from the soucecode,but the exception exist;

    maybe something wrong in central directory when ZipFile read all entries,but ZipInputStream do fine ? sorry i didn't read the zip file format doc.

    ii)if (ms.Length > ze.Size) the line code is to process some zipfile(mayb invalid format?),those file cause the zis stream to read more data than the size.Now ,i can't find these zipfiles,if i finded ,maybe i could send a sample to you . And these line no affect current problem.

     

    Best regards,

    airwolf

       

  • 11-18-2013 11:21 AM In reply to

    Re: Use ZipFile to decompress a largefile throw wrong local header

    Another background:

    The file is from ios app archive,aka IPA Backup ,and the ipa contain large document data.

     

    thanks again.

  • 11-19-2013 6:15 AM In reply to

    Re: Use ZipFile to decompress a largefile throw wrong local header

    Hi,

    As you realise by now, the problem is specific to this zip file. Have you checked it with Winzip > Properties > Details ?

    Also, if you wished to make it available to me I could investigate further.

     

    Thanks, David

  • 11-19-2013 6:17 AM In reply to

    Re: Use ZipFile to decompress a largefile throw wrong local header

    airwolf2026:
    maybe something wrong in central directory when ZipFile read all entries,but ZipInputStream do fi

    Yes, good diagnosis, that is very likely to be the case. ZipInputStream uses the local headers while ZipFile first checks the Central Header.

     

  • 11-21-2013 2:41 AM In reply to

    Re: Use ZipFile to decompress a largefile throw wrong local header

    Hi,

    David,

    Luckily,i found a site to share the large file ,if you have time  to investigate further,

    you could download it from here http://url.cn/NdBltz  ,or the full url http://share.weiyun.com/eaa8d81a92d557879b20dfd69a727d39 

    the zip file is a IPA(iOS App).

    I has check it with winzip,it says "Error: central directory not found."so,i close the file share.

    Thanks for your great work.

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