Skip to content

CreateZip an empty file produces a corrupted zip file. #391

Closed

Description

@s-morita-being

Steps to reproduce

  1. Compress an empty file using FastZip.CreateZip.
  2. Extract the created zip file using FastZip.ExtractZip or any other unzip tool.

or

  1. Extract the attached SharpZipTest.zip.
  2. Run SharpZipTest.FastZipTests.TestCompressFile("").

Expected behavior

Successfully get the empty file extracted.

Actual behavior

Got ICSharpCode.SharpZipLib.Zip.ZipException : Wrong local header signature @3

Version of SharpZipLib

1.2.0

Obtained from (only keep the relevant lines)

  • Package installed using NuGet

Activity

  1. Numpsy commented on Oct 13, 2019

    @Numpsy
    Contributor

    I think this is a variant of #382, but for ZipOutputStream rather than GZipOutputStream (revealed by the same Deflator change, but possibly an existing issue), whereby:

    • When FastZip adds the 0 length entry to ZipOutputStream, the compression method gets set to Stored.
    • The stream copy utility function that FastZip uses to write file entries flushes the ZipOutputStream, even though no data was written for the entry.
    • The call to Flush goes through to the base DeflatorOutputStream, which flushes the Deflator into the base stream even though there is no Deflation in use.

    The change to the deflator behaviour in #225 might have caused this process to write some data into an entry that is supposed to be 0 length causing the data structure in the output stream to be wrong, but in any case, I wou;dn't have thought that flushing ZipOutputStream should flush the Deflator when working on a Stored entry anyway?

  2. piksel commented on Dec 30, 2019

    @piksel
    Member

    Confirmed and added a test (that fails). Will probably be solved in #398

  3. added
    fixed in next
    on Dec 31, 2019
  4. piksel commented on Nov 21, 2020

    @piksel
    Member

    Fixed by #406

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugduplicatefixed in next

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions