Skip to content

Invalid CRC/Length when using compression mode = 0 and file size > 4 gigs #130

Closed

Description

@Jon-Murray

Steps to reproduce

  1. Use the IIS file server example (or any examples found online) to write to a http response stream (I have not tried this with a file)
  2. Write a series of chunks to the stream, making sure that the eventual total file size is > 4 gigs
  3. Extract the file and you will get a number of errors, CRCs failing, etc. If the file is < 4 gigs, then there are no problems at all.

Expected behavior

The file should extract cleanly. Using the same code but setting the compression level to > "1" fixes the CRC/final lengths.

Actual behavior

CRC is invalid, compressed file length is like ~200 meg (instead of 4.2 gigs). Note that although it fixes for me setting the compression to >= 1, adding an additional 700mb file will also cause failures. Using the same code as below, but adding say a 700 MB file and 2x 50MB files to the directory will download and extract with no problems at all. Adding the 4+gig file and then 2 50MB files to the same directory (again, using compression >= 1) will break the zip.
I am running on Windows server 2012 64 bit, and using the latest version of 7 zip for testing. I am also using 2x ISO files (4GB, 750MB) and 2x music files (50MB, 50MB) for testing, if that matters.
The errors are "unconfirmed start of archive", "some data after the end of the payload data" and "CRC failed"

Version of SharpZipLib

0.86.0 from NuGet, but I have also tried this with the latest version on the website compiled from source.

Obtained from (place an x between the brackets for all that apply)

  • Compiled from source
    • branch: _______
    • commit: _______
  • Downloaded DLL from GitHub
  • Downloaded DLL from SourceForge
  • Downloaded DLL from _______
  • DLL included as part of
  • Package installed using:
    • [ x ] NuGet
    • MyGet
    • Chocolatey

nb. I've included the code here for debugging but it should not really be necessary. This code looks "old" as i've spent the past few hours looking around and trying several examples from anywhere/everywhere. This is just ripped from stackoverflow. Also nb. i've also tried setting UseZip64 to dynamic, and on (and even off, lol) to try and address this; it does not make a difference. Other than that, it is working perfectly and is a great library, so i wanted to say thanks for all your hard work, and apologies for the whiny friday night bug post!

#region Working, but not with 4gig+ files
string path = @"C: \Users\Administrator\Downloads\nu";

Response.Clear();
Response.ContentType = "application/zip";
Response.AddHeader("Content-Disposition", string.Format("attachment; filename=\"{0}\"", "hive.zip"));
Response.BufferOutput = false;

byte[] buffer = new byte[1024 * 1024];
using (ZipOutputStream zo = new ZipOutputStream(Response.OutputStream, 1024 * 1024))
{
    //zo.UseZip64 = UseZip64.On;
    zo.SetLevel(1); // nb. setting this to 1 or above will fix the issue
    DirectoryInfo di = new DirectoryInfo(path);
    foreach (string file in Directory.GetFiles(di.FullName, "*.*", SearchOption.AllDirectories))
    {
        string folder = Path.GetDirectoryName(file);
        if (folder.Length > di.FullName.Length)
        {
            folder = folder.Substring(di.FullName.Length).Trim('\\') + @"\";
        }
        else
        {
            folder = string.Empty;
        }
        ZipEntry entry = new ZipEntry(file);
        entry.Size = new FileInfo(file).Length;

        zo.PutNextEntry(entry);

        using (FileStream fs = System.IO.File.OpenRead(file))
        {
            ICSharpCode.SharpZipLib.Core.StreamUtils.Copy(fs, zo, buffer);
        }

        zo.Flush();
        zo.CloseEntry();

        Response.Flush();
    }

    zo.Finish();
    zo.Flush();

    Response.End();
    return new EmptyResult();  
}

Activity

  1. self-assigned this
    on Aug 14, 2016
  2. insylogo commented on Apr 26, 2018

    @insylogo
    Contributor

    I think this is the same as 164

  3. piksel commented on Oct 3, 2020

    @piksel
    Member

    Yep, both a duplicate and fixed in #226

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions