mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-11 05:24:56 +00:00
Bug version 0.28.1: IReader.MoveToNextEntry() is not working with encrypted zip files #446
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @mbihler on GitHub (Mar 30, 2021).
In Version 0.27.1 IReader.MoveToNextEntry() was working well with encrypted zip files
When project is updated to 0.28.1, the method is only working once and is returning false after first file has been extracted.
The problem seems to be with encrypted zip files only:
Example:
`using Stream stream = File.OpenRead(@"C:\Temp\SharpCompressTest\SharpCompressTest.zip");
var reader = ReaderFactory.Open(stream, new ReaderOptions { Password = "1234" });
// Version 0.28.1: While loop will only extract first file instead of all files
while (reader.MoveToNextEntry())
{
reader.WriteEntryToDirectory(@"C:\Temp\SharpCompressTest", new ExtractionOptions()
{
ExtractFullPath = true,
PreserveFileTime = true
});
}`
@hungyiloo commented on GitHub (Apr 13, 2021):
I think I'm experiencing this issue too. I thought it was #514 so I posted my findings there: https://github.com/adamhathcock/sharpcompress/issues/514#issuecomment-818490327
@adamhathcock commented on GitHub (Apr 24, 2021):
This is weird because I have a test that literally tests this. If you could post a sample file, that would be helpful. Here's the test:
@mbihler commented on GitHub (Apr 24, 2021):
I think I have found the constellation where the error occurs:
It only occurs if the ZIP file has been encrypted with ZipCrypto. With AES-256 all is working.
I used the code of your test method: With 0.28.1 just one file will be decrypted - with 0.27.1 all is fine.
@hungyiloo commented on GitHub (Apr 25, 2021):
I can confirm that zipping the same collection of files with ZipCrypto vs AES-256 and running that unit test does replicate the issue on my side too (i.e. only one file extracted when ZipCrypto, totally fine with AES-256). Further to that, the
Assertalso fails sincereader.Entry.CompressionTypereturnsNoneinstead ofUnknown.I'm guessing some zip tools, namely some versions of Windows, might still use ZipCrypto as the default despite its weakness?
Here are my test zip files, both with password "test". Hope it helps.
aes256.zip
zipcrypto.zip
(Note that you can easily create both types of zip files using 7-zip file manager)
@adamhathcock commented on GitHub (Apr 25, 2021):
Found the issue which was because of a recent change and fixed it: https://github.com/adamhathcock/sharpcompress/pull/593
@adamhathcock commented on GitHub (Apr 25, 2021):
fix released in 0.28.2
@LancerComet commented on GitHub (Dec 18, 2022):
I'm still facing this problem with 0.32.2, AES256-encrypted zip files are fine but not ZipCrypto-encrypted.
I ended up switching back to Archive API from Reader API again.
@adamhathcock commented on GitHub (Dec 19, 2022):
Odd. The test explicitly tests that. I wonder if I have some type issues so it's still using the Span method
@LancerComet commented on GitHub (Dec 19, 2022):
I'm using SharpCompress in an UWP project, does it matter?
The ZipCrypto arichive is created by Bandizip with default setting.
@adamhathcock commented on GitHub (Dec 20, 2022):
UWP is slightly different than other other environments. I'll take a closer look but I'd also see if your code can decrypt the file on the regular .NET runtime.
@LancerComet commented on GitHub (Dec 20, 2022):
I've created a .NET 7 console app and it turned out Reader API doesn't work properly:
with Archive API:
PS: What's going on with AES256 one:
@adamhathcock commented on GitHub (Dec 20, 2022):
Still should be the same as
Zip_Deflate_ZipCrypto_ReadAny chance of sharing the file? Is it this specific one or all?
@LancerComet commented on GitHub (Dec 20, 2022):
Sure, the ZipCrypto one is here: 1.ZipCrypto.zip
Password is just "password"
Every single archive I've created using Bandizip with ZipCrypto encryption doesn't work properly, like:

@adamhathcock commented on GitHub (Dec 21, 2022):
Actually, I think Bandizip is creating bad Zip files.
All the entries are flagged as having a post data descripter header even though they do not.
You can see the Flags of headers having
UsePostDataDescriptorset but looking at the file there is no header. So the Reader code assumes it exists.Archive API works because it uses the dictionary at the end of the file to seek to the entries instead of streaming through the file.
@LancerComet commented on GitHub (Dec 21, 2022):
Indeed. I didn't see there was a
UsePostDataDescriptorflag on every single entry from the zip file which was created by 7-Zip, and this file can be decoded by Reader API properly.Thanks for your hard work, maybe I have to send Bandizip an email.
@kippler commented on GitHub (Dec 23, 2022):
Hello. I'm a developer of Bandizip.
It's an Info-zip's modification of bit3.
I made a sample zip file with the same problem using this command-line in Ubuntu.
zip -e -X infozip.zip a.txt b.txt
infozip.zip (passwd=aaaa)
This is the comment for the bit3 in 7zip source.
@adamhathcock commented on GitHub (Dec 23, 2022):
that totally breaks streaming zip reading:
@kippler commented on GitHub (Dec 24, 2022):
I know it's weird. I was confused too when I faced a sample of such type.
APPNOTE says "MUST exist" but info-zip is a de facto too.
Info-zip's modification has an advantage when you create an encrypted ZIP file.
For example, make a big file ( fsutil file createnew bigfile 100000000000 ) and
compress it using 7zip with a password, the progress bar will stop until getting the CRC of the file.
So, the modification is suitable to create streaming ZIP.
@adamhathcock commented on GitHub (Jan 3, 2023):
@kippler what do you do for streaming zips altogether then? Or does Bandi-zip just not care about the trailer for streaming zips at all?
I'm not sure what to do here. You could say "Reader with Encrypted" isn't supported or add a custom option for these use cases.
It's really silly that info-zip modified an existing, well documented bit flag.
@kippler commented on GitHub (Jan 3, 2023):
In most cases, Bandizip checks the central header instead of the local header.
Bandizip opens ZIP in streaming mode only when the central header is broken, and here is the rule I use.
bit0:0 bit3:1 -> Data descriptor exists.
bit0:1 bit3:0 -> Encrypted. No data descriptor. Password checker is CRC
bit0:1 bit3:1 -> Encrypted. No data descriptor. Password checker is dostime.
I agree with you. It's so silly, but what can I do?
Linux and macOS use info-zip.
@adamhathcock commented on GitHub (Mar 1, 2023):
I'll look into implementing the above. Been out of it for personal reasons.
@idan-weiss commented on GitHub (Feb 7, 2024):
I still experience this issue, version 0.35.0