adamhathcock / sharpcompress

SharpCompress is a fully managed C# library to deal with many compression types and formats.
MIT License
2.26k stars 479 forks source link

Exception thrown when password is invalid #553

Open adras opened 3 years ago

adras commented 3 years ago

Throwing and catching of exceptions is extremely slow. Therefore one of the rules in programming is to not use exception for flow control.

It'd be great if there's a proper return value to check indicating whether it was extracted or not and the reasons for that.

For instance: entry.WriteToDictionary returns void, it could however return something like: Class ExtractionResult { bool success; ExtractionErrors error }

enum ExtractionErrors { InvalidPassword, NotEnoughDiskspace NoPermissions etc.... }

Why I care? To be honest, I'm trying to bruteforce the password of a zip file. Where my password generator is able to get to "aaaaaa" in 2 seconds, it ends up at "nx" after 30 seconds because the exception handling is so slow.

adamhathcock commented 3 years ago

You're welcome to make a PR that gives proper feedback from the password code all the way in the external code without an exception. It's a pretty major refactor to do it.

Exceptions were used because for most use cases, it is exceptional. Brute forcing a password isn't a use case I envisioned for this.

adras commented 3 years ago

Thanks for your reply. I was actually looking into that yesterday, but I gave up after 5 minutes because I wasn't able to compile the solution. I'm not blaming anyone, but solutions that work out of the box are getting rarer and rarer nowadays :( It seems like it's an art nobody cares about anymore