sharpcompress
sharpcompress copied to clipboard
Checking if a 7z file is encrypted will crash
Create a 7z file:
$ 7zz a test.7z
Check the entries are encrypted:
Scratch.fsx
#r "nuget: SharpCompress, 0.33.0"
open SharpCompress
open SharpCompress.Archives
let archive = ArchiveFactory.Open("test.7z")
for e in archive.Entries do
printfn $"IsEncrypted %b{e.IsEncrypted}"
$ dotnet fsi ./Scratch.fsx
It will crash:
System.NullReferenceException: Object reference not set to an instance of an object.
at SharpCompress.Common.SevenZip.SevenZipFilePart.get_IsEncrypted()
at SharpCompress.Common.SevenZip.SevenZipEntry.get_IsEncrypted()
To see if I recreated the issue correctly, if you check if it is a directory before checking the IsEncrypted flag
if not e.IsDirectory then
Does that do anything for you?
This does not crash:
#r "nuget: SharpCompress, 0.33.0"
open SharpCompress
open SharpCompress.Archives
let archive = ArchiveFactory.Open("test.7z")
for e in archive.Entries do
if e.IsDirectory then
printfn $"%A{e} is a directory"
else
printfn $"IsEncrypted %b{e.IsEncrypted}"
Perhaps the error message should be improved?
Can a directory be encrypted?
This was fixed: https://github.com/adamhathcock/sharpcompress/pull/768