-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Detect password protected file with ZipArchive #57197
Comments
Tagging subscribers to this area: @dotnet/area-system-io-compression Issue DetailsCurrently if a file is not able to be decompressed, there is no information given in the exception regarding if it was password protected file. Expected outcome: Provide the reason for failure in extracting text for zip files, eg: A file was password protected etc
|
Triage: related to #1545, marked as "Bottom Up" to hopefully include it in .NET 7 |
@srikrishnag Could you provide a little more detail for how you'd like to have this reason exposed? Likely the most efficient thing is for you to show some code where you're currently using the System.IO.Compression APIs to decompress, highlighting what "failure" looks like now, and illustrating what you'd like the API call to do differently to make the reason available. I suspect we'll want to find an approach that somehow:
I'm not sure what that could look like though. Thanks! |
We're using the code as below:
|
If your intent is to still handle the exception and interrogate it to determine if it was caused by password protected error vs. another error, then we could consider using However, from a cursory peek through the implementation, I'm seeing that the native layer is surfacing the "unknown compression method" error that results in the In the exception handling approach, we'd also need to think this through from a threat modeling perspective--would including a flag in the exception that indicates the archive was password protected allow anything to leak out that could be used maliciously? 🤔 Another approach would be through new APIs related to #1545 where we want to support password-protected zip archives. In the scenario you're describing, you don't know the password or encryption algorithm, so the specific APIs proposed on that issue would not suffice. I think this leads to the inevitable conclusion that you need a new API that exposes the encryption mode for the entry/archive. Then before calling @carlossanlop Do you have other thoughts on how this could be approached? |
my read is user wants System.NotSupportedException with message "Password protected archives are not supported", until #1545 is forged into a reality. this (parse-like analysis) can be done without new public api. |
I'm not sure Checking/parsing exception messages is a very brittle approach, and it's discouraged. While I understand the motive for having a light-touch change to accomplish this, we also need to think about this from the "if we were designing this from scratch, how would we design it" angle. Then we can potentially look for a bridge. Since this is about control flow, I don't think we'd start with an exception-based design. "DO NOT use exceptions for the normal flow of control, if possible" |
Internal request from 3 partners: https://dev.azure.com/devdiv/DevDiv/_workitems/edit/1486845 |
This is not always true, I have decompressed ZipCrypto (weak) encrypted entries without exception being thrown but the result is a garbled file content. We should take into account if the solution to this problem may action a change in our existing one-liner APIs e.g: |
@srikrishnag - Can you review the API that was approved to confirm that it would meet your needs? It is a very minimal addition, simply adding a Please note that this new API would be available in .NET 7+. |
Currently if a file is not able to be decompressed, there is no information given in the exception regarding if it was password protected file.
Expected outcome: Provide the reason for failure in extracting text for zip files, eg: A file was password protected etc
The text was updated successfully, but these errors were encountered: