Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

Commit

Permalink
Fixed issue when appending encrypted files to a stream.
Browse files Browse the repository at this point in the history
  • Loading branch information
squid-box committed Mar 22, 2023
1 parent fccecd6 commit 2fa34a7
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
23 changes: 23 additions & 0 deletions SevenZip.Tests/SevenZipCompressorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -377,5 +377,28 @@ public void AppendToArchiveWithEncryptedHeadersTest()

compressor.CompressFilesEncrypted(TemporaryFile, "password", @"TestData\zip.zip");
}

[Test]
public void AppendEncryptedFileToStreamTest()
{
using var fileStream = new FileStream(TemporaryFile, FileMode.Create);

var compressor = new SevenZipCompressor
{
ArchiveFormat = OutArchiveFormat.SevenZip,
CompressionMethod = CompressionMethod.Lzma2,
CompressionMode = CompressionMode.Append,
ZipEncryptionMethod = ZipEncryptionMethod.Aes256,
CompressionLevel = CompressionLevel.Normal,
EncryptHeaders = true
};

compressor.CompressFilesEncrypted(fileStream, "password", @"TestData\zip.zip");

using var extractor = new SevenZipExtractor(TemporaryFile, "password");

Assert.AreEqual(1, extractor.FilesCount);
Assert.AreEqual("zip.zip", extractor.ArchiveFileNames[0]);
}
}
}
2 changes: 1 addition & 1 deletion SevenZip/LibraryManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ public static IInArchive InArchive(InArchiveFormat format, object user)
{
lock (_syncRoot)
{
if (_inArchives[user][format] == null)
if (!_inArchives.ContainsKey(user) || _inArchives[user][format] == null)
{
#if NET472 || NETSTANDARD2_0
var sp = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
Expand Down

0 comments on commit 2fa34a7

Please sign in to comment.