mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-03 21:23:38 +00:00
RarRijndael throws NullReferenceException when there is no password #461
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 @IS4Code on GitHub (May 15, 2021).
Rar parsing (via RarReader, haven't tested other archive types) has a bug when the password is not set (null) and the archive is encrypted. When the header is encrypted too, it correctly throws
CryptographicException, but when only the files are encrypted,MoveToNextEntrythrowsNullReferenceException, as it attempts to initialize the engine with a null password.I could use a blank password, but this breaks encrypted headers, as it cannot determine the format. I would prefer a
CryptographicExceptionthrown when an encrypted file is opened without a password (but its entry should be accessible).Ideally, there should be some sort of wrong password detection as well, but fixing the first bug is completely sufficient.
@adamhathcock commented on GitHub (Jun 4, 2021):
I'll accept a PR for this.
I think there isn't a good way (or used not to be) to detect encrypted files so an explicit exception wasn't done at the time.
@Nanook commented on GitHub (May 4, 2022):
I noticed this issue and found that checking IsEncrypted on the Entry was the best method. If you're not using passwords then you should not attempt to process an Entry with IsEncrypted is True.
If the archive is encrypted with encrypted filenames then catching SharpCompresses CryptographicException when no password is set indicates it's passworded. #663 aligns 7zip to this behaviour also.
I've only tested this behaviour with Archive Open(), but is should be the same for RarReader too.
@IS4Code commented on GitHub (May 4, 2022):
Yes, it makes sense not to open an encrypted entry, but as I said,
MoveToNextEntryitself throws the exception. Iterating the entries and retrieving their metadata should be still valid even without a password.