protected Archive getArchive() {
ArchiveLoadOptions loadOptions = new ArchiveLoadOptions();
if (encoding != null) {
loadOptions.setEncoding(encoding);
}
if (decryptionPassword != null) {
loadOptions.setDecryptionPassword(decryptionPassword);
}
return new Archive(zipInputStream, loadOptions);
}
The problem is the following:
If I provide the correct password (“password” in this case), the extraction works.
If I provide a wrong password (for example, “wrong”), the extraction fails as expected, but with an internal error. (com.aspose.zip.private_.aw.s: Bad state (invalid block type)
I would expect it to crash with an “InvalidDataException”, since I want to diversify between errors due to wrong password or other unexpected errors (crashes, corrupted zips, …)
I would hence please ask if it were possible to fix the bug
It seems that you are encountering an issue where providing an incorrect password for a zip file results in an internal error instead of the expected InvalidDataException. This behavior is indeed a known bug when using the store (no compression) method for zip extraction.
The development team has acknowledged this issue and has opened a ticket to address it. They plan to implement a fix, which is expected to be included in a future version of the library. In the latest version (23.5), the library should raise an exception when attempting to extract with a wrong password, which should help differentiate between incorrect passwords and other unexpected errors.
To summarize, if you are using a version prior to 23.5, you may experience this internal error. Upgrading to the latest version should resolve the issue and provide the expected behavior.
If you need further assistance or have additional questions, feel free to ask!
This is higher than 23.5, so there is clarely a bug.
To have more information in order to reproduce the bug:
the zip is attached
try to extract with pwd “wrong” instead of the correct “password”
stack given by the code
com.aspose.zip.private_.aw.s: Bad state (invalid block type)
at com.aspose.zip.private_.aw.k.a(Unknown Source)
at com.aspose.zip.private_.aw.r.a(Unknown Source)
at com.aspose.zip.private_.aw.q.a(Unknown Source)
at com.aspose.zip.private_.aw.f.a(Unknown Source)
at com.aspose.zip.cp.a(Unknown Source)
at com.aspose.zip.qe.a(Unknown Source)
at com.aspose.zip.Archive.extractToDirectory(Unknown Source)
@mrossi
We have opened the following new ticket(s) in our internal issue tracking system and will deliver their fixes according to the terms mentioned in Free Support Policies.
Issue ID(s): ZIPNET-1251
You can obtain Paid Support Services if you need support on a priority basis, along with the direct access to our Paid Support management team.
A part from this error, is it right to assume that if the “InvalidDataException” is thrown, the problem is that the zip is encrypted and the passed password is wrong?
For now, in case of failure, I’m running the same unzipping by passing “null” as password. If I receive the ArgumentNullException I assume that the reason is that the zip is password protected.
Are these assumptions correct? If they are not could you provide counterexamples?
Thanks in advance
InvalidDataException can be raised in case when data or headers of archive is corrupted, and decompression algorithm fails to proceed.
The correct way to determine whether ZIP archive password protected is to check does its entry has type ArchiveEntryEncrypted: if (archive.Entries[0] is ArchiveEntryEncrypted) {...}
In theory, ZIP standard allows entries be encrypted independently, so while some entries are encrypted other are not. Aspose.ZIP can extract such “mixed” archives. In practice, usually whole archive whether encrypted or not.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
Enables storage, such as cookies, related to analytics.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.
Sets consent for personalized advertising.
Cookie Notice
To provide you with the best experience, we use cookies for personalization, analytics, and ads. By using our site, you agree to our cookie policy.
More info
Enables storage, such as cookies, related to analytics.
Enables storage, such as cookies, related to advertising.
Sets consent for sending user data to Google for online advertising purposes.