haf / DotNetZip.Semverd

Please use System.IO.Compression! A fork of the DotNetZip project without signing with a solution that compiles cleanly. This project aims to follow semver to avoid versioning conflicts. DotNetZip is a FAST, FREE class library and toolset for manipulating zip files. Use VB, C# or any .NET language to easily create, extract, or update zip files.
Other
545 stars 218 forks source link

Password Protected Files; Read Fails When Position Not a Multiple of 16 #253

Open legistek opened 2 years ago

legistek commented 2 years ago

For password-protected Zip files, I am finding that I cannot Read accurate data from the CrcCalculatorStream unless the position is a multiple of 16.

To reproduce:

            Random rand = new Random();
            byte[] buffer = new byte[1048576];

            long remaining = ZipEntryStream.Length;            
            while (remaining > 0)
            {
                int take = 524288 + rand.Next(524288);
                var read = ZipEntryStream.Read(buffer, 0, (int)Math.Min(remaining, take));
                if (read == 0)
                    break;
                _outputStream.Write(buffer, 0, read);
                remaining -= read;
            }

I assume this is related to the block size for the AES encryption. My guess is that the internal Read method is incorrectly starting decryption at the byte actual stream position rather than at the beginning of the block.

I am able to work around this by wrapping it in a BufferedStream with a size divisible by 16 but this is probably something that should be looked at. Thanks!