Skip to content
This repository has been archived by the owner on May 15, 2024. It is now read-only.

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

Open
legistek opened this issue Mar 20, 2022 · 0 comments
Open

Comments

@legistek
Copy link

legistek commented Mar 20, 2022

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!

@legistek legistek changed the title Password Protected Files; Cannot Perform Reads with Different Lengths Password Protected Files; Cannot Perform Reads With Lengths Not Divisible by 16 Mar 20, 2022
@legistek legistek changed the title Password Protected Files; Cannot Perform Reads With Lengths Not Divisible by 16 Password Protected Files; Cannot Perform Successive Reads of Lengths Not Divisible by 16 Mar 20, 2022
@legistek legistek changed the title Password Protected Files; Cannot Perform Successive Reads of Lengths Not Divisible by 16 Password Protected Files; Read Fails When Position Not a Multiple of 16 Mar 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant