ZipOutputStream corrupts data buffer when calling Write(byte[],int,int)

Jan 7, 2011 at 2:18 PM

First off, thanks for the brilliant library and all the effort that has gone into it.

I've found that when I write data to a ZipOutputStream the data buffer is corrupted afterwords. I've looked through the documentation, but didn't find a warning indicating that such a side-effect is intended. Is this due to the encryption I'm enabling?

Here is a little example which reproduces the problem. If I use ZipFile instead of ZipOutputStream the buffer doesn't get corrupted.

var content = new byte[1789];
unchecked
{
    byte b = 0;
    for (var i = 0; i < content.Length; i++, b++)
    {
        content[i] = b;
    }
}

using (var fileStream = File.OpenWrite("temp.zip"))
{
    using(var zipStream = new ZipOutputStream(fileStream, true))
    {
        zipStream.CompressionLevel = CompressionLevel.None;
        zipStream.Password = "mydummypassword";
        zipStream.Encryption = EncryptionAlgorithm.WinZipAes256;
        zipStream.PutNextEntry("myentry.myext");
        zipStream.Write(content, 0, content.Length);
    }
}

unchecked
{
    byte b = 0;
    for (var i = 0; i < content.Length; i++, b++)
    {
        if (content[i] != b)
        {
            Console.WriteLine("Buffer was modified.");
        }
    }
}

Coordinator
Jan 12, 2011 at 2:31 AM

That is unexpected; it seems like a bug in DotNetZip.

Coordinator
Jan 12, 2011 at 2:32 AM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Jan 12, 2011 at 7:11 AM

Thanks, I'm using WriteByte(byte) in the meantime, but I expect that Write(byte[], int, int) will perform faster.