Checking if a 7z file is encrypted will crash #583

Open
opened 2026-01-29 22:14:09 +00:00 by claunia · 3 comments
Owner

Originally created by @njlr on GitHub (Sep 14, 2023).

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()
Originally created by @njlr on GitHub (Sep 14, 2023). Create a `7z` file: ```bash $ 7zz a test.7z ``` Check the entries are encrypted: `Scratch.fsx` ```fsharp #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}" ``` ```bash $ 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() ```
Author
Owner

@Erior commented on GitHub (Sep 23, 2023):

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?

@Erior commented on GitHub (Sep 23, 2023): 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?
Author
Owner

@njlr commented on GitHub (Sep 26, 2023):

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?

@njlr commented on GitHub (Sep 26, 2023): This does not crash: ```fsharp #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?
Author
Owner

@adamhathcock commented on GitHub (Sep 26, 2023):

This was fixed: https://github.com/adamhathcock/sharpcompress/pull/768

@adamhathcock commented on GitHub (Sep 26, 2023): This was fixed: https://github.com/adamhathcock/sharpcompress/pull/768
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#583