-
Notifications
You must be signed in to change notification settings - Fork 976
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Async entry read causes exception when reading AES encrypted zip. #823
Comments
Thanks for the report and for actually using the dotnet fiddle template! ArchiveDiag report for the file (nothing stands out afaikt): I have not found I cause yet, but I will look into this as soon I can. |
Yeah, this is yet another time that the framework bypasses the public methods of Stacktrace
, This is essentially #572 all over again, but with no clear solution. |
As for consumers (including @rilehudd), you can replace the var entry = zip.GetEntry("abcdefgh.txt");
var entryStream = zip.GetInputStream(entry);
var entryBuffer = new byte[entry.Size];
using (var ms2 = new MemoryStream(entryBuffer))
{
byte[] buffer = new byte[81920];
int read;
while ((read = await entryStream.ReadAsync(buffer, 0, buffer.Length)) > 0)
{
ms2.Write(buffer, 0, read);
}
var output = Encoding.UTF8.GetString(entryBuffer);
// ... use output ...
} It's not ideal, for sure, but that is the only async path that avoids the optimisations in .NET that bypasses the AES encryption logic. |
Is there a way we can detect this "bypassed" state an compensate for this optimization? Otherwise, it seems like this might be an optimization that might likely affect many encryption stream implementations. Do you think it makes sense to submit this optimization bug upstream to dotnet? |
Sorry didn't intend to close this issue (wanted to ensure you see this and have an opportunity to respond so I might see what your thoughts are). |
I think the main issue is that extending |
Thanks for taking the time to take a look at this! |
There is another solution to this. The compression method that is used for the entry is STORE, which means that it's uncompressed. This problem only happens to such entries because we directly return the |
Describe the bug
When trying to read an encrypted archive's entry's input stream asynchronously, it reports an exception containing message: "Auth code missing from input stream".
Yet, if the same archive is read synchronously it works fine.
Reproduction Code
https://dotnetfiddle.net/RhJM7o
Steps to reproduce
It doesn't seem to happen for every input. But for inputs where it does happen, changing the async call to the synchronous version fixes the problem.
The zip input is in the dotnetfiddle.
The steps to create the zip archive from 7-Zip are:
Expected behavior
For the same input, I expected them both to work (the synchronous and the asynchronous).
Operating System
Windows
Framework Version
.NET 6
Tags
ZIP, Encryption, Async
Additional context
No response
The text was updated successfully, but these errors were encountered: