Can't extract encrypted 7z LZMA2 files #155

Open
opened 2026-01-29 22:07:28 +00:00 by claunia · 10 comments
Owner

Originally created by @ciriousjoker on GitHub (Feb 5, 2017).

I have an encrypted 7zip archive (linked below) encrypted with the password "dontgoout", but whenever I try to extract it, it throws an error at MoveToNextEntry.

Here's a screenshot of the stack trace:
https://gyazo.com/6fb0b0c0731d6e23d04a26e301cc2dbe

I created the archive using the 7zip client for Windows using these settings:
https://gyazo.com/ca4e67e6a259d79cdf0675dc42fd8268

Original name was 0.tmp, but Github only allows zip files.
0.tmp.encrypted.zip

Extracting the same archive without any password works perfectly fine and I can extract the encrypted 7z archive using the 7zip desktop client, so this has to be a bug in the library (Or I'm just too dumb for life and I missed something I should have done)

Here's the code I used to extract that archive:

SharpCompress.Readers.ReaderOptions test = new SharpCompress.Readers.ReaderOptions();
test.LookForHeader = true;
test.LeaveStreamOpen = false;
test.Password = "dontgoout";

var archive = SevenZipArchive.Open(filename, test);

if (!archive.IsComplete)
{
    MessageBox.Show("One of the downloaded resources is corrupt, please try again.");
    return;
}

long totalbytes = archive.TotalUncompressSize;
long processedbytes = 0;

var reader = archive.ExtractAllEntries();

while (reader.MoveToNextEntry()) // <-- Here it crashes
{
    if (!reader.Entry.IsDirectory)
    {
Originally created by @ciriousjoker on GitHub (Feb 5, 2017). I have an encrypted 7zip archive (linked below) encrypted with the password "dontgoout", but whenever I try to extract it, it throws an error at MoveToNextEntry. Here's a screenshot of the stack trace: https://gyazo.com/6fb0b0c0731d6e23d04a26e301cc2dbe I created the archive using the 7zip client for Windows using these settings: https://gyazo.com/ca4e67e6a259d79cdf0675dc42fd8268 Original name was 0.tmp, but Github only allows zip files. [0.tmp.encrypted.zip](https://github.com/adamhathcock/sharpcompress/files/752673/0.tmp.encrypted.zip) Extracting the same archive without any password works perfectly fine and I can extract the encrypted 7z archive using the 7zip desktop client, so this has to be a bug in the library (Or I'm just too dumb for life and I missed something I should have done) Here's the code I used to extract that archive: ``` SharpCompress.Readers.ReaderOptions test = new SharpCompress.Readers.ReaderOptions(); test.LookForHeader = true; test.LeaveStreamOpen = false; test.Password = "dontgoout"; var archive = SevenZipArchive.Open(filename, test); if (!archive.IsComplete) { MessageBox.Show("One of the downloaded resources is corrupt, please try again."); return; } long totalbytes = archive.TotalUncompressSize; long processedbytes = 0; var reader = archive.ExtractAllEntries(); while (reader.MoveToNextEntry()) // <-- Here it crashes { if (!reader.Entry.IsDirectory) { ```
claunia added the bug label 2026-01-29 22:07:28 +00:00
Author
Owner

@adamhathcock commented on GitHub (Feb 5, 2017):

I was about to say "sharpcompress doesn't support encrypted 7zip files" but honestly I can't remember.

However, the error you got is fixable because it's using a stream that doesn't support seeking though 7zip requires seeking.

@adamhathcock commented on GitHub (Feb 5, 2017): I was about to say "sharpcompress doesn't support encrypted 7zip files" but honestly I can't remember. However, the error you got is fixable because it's using a stream that doesn't support seeking though 7zip requires seeking.
Author
Owner

@ciriousjoker commented on GitHub (Feb 5, 2017):

But if the library requires seekable streams (which totally makes sense the way 7z works), why did it work with unencrypted files? I mean they'd have to be seekable too, right?

@ciriousjoker commented on GitHub (Feb 5, 2017): But if the library requires seekable streams (which totally makes sense the way 7z works), why did it work with unencrypted files? I mean they'd have to be seekable too, right?
Author
Owner

@ciriousjoker commented on GitHub (Feb 5, 2017):

Woops

@ciriousjoker commented on GitHub (Feb 5, 2017): Woops
Author
Owner

@adamhathcock commented on GitHub (Feb 5, 2017):

It must be that the decryption code just needs to know the length for some reason and it's using a different stream class.

The class with the error is one I wrote for the purpose of ensuring no seekable stream was used in other parts of the code.

I haven't done much with the 7zip code personally. I really hate the 7zip archive format.

@adamhathcock commented on GitHub (Feb 5, 2017): It must be that the decryption code just needs to know the length for some reason and it's using a different stream class. The class with the error is one I wrote for the purpose of ensuring no seekable stream was used in other parts of the code. I haven't done much with the 7zip code personally. I really hate the 7zip archive format.
Author
Owner

@ciriousjoker commented on GitHub (Feb 5, 2017):

Can you point me in the right direction please? I tried using your API examples, but they only seem to work with zip archives ..

(Aka replacing
var archive = ...;
with
var archive = ArchiveFactory.Open(...);
doesn't work either)

SevenZipArchive.Open(new FileStream(...));
also didn't work

@ciriousjoker commented on GitHub (Feb 5, 2017): Can you point me in the right direction please? I tried using your API examples, but they only seem to work with zip archives .. (Aka replacing var archive = ...; with var archive = ArchiveFactory.Open(...); doesn't work either) SevenZipArchive.Open(new FileStream(...)); also didn't work
Author
Owner

@adamhathcock commented on GitHub (Feb 5, 2017):

It's not going to work without a code change. You're going to get the exception you posted always with that encrypted 7zip file

@adamhathcock commented on GitHub (Feb 5, 2017): It's not going to work without a code change. You're going to get the exception you posted always with that encrypted 7zip file
Author
Owner

@ciriousjoker commented on GitHub (Feb 5, 2017):

So I'd have to fix your library? Or are you saying that my encrypted 7zip file is broken?

By the way, no matter what 7zip file I use (encrypted or not doesn't matter), I get this weird thing in the locals tab:

https://gyazo.com/363d6b37b9dd0ff79df69d602d04fa52

Not sure if it has something to do with this error, but it always throws that error. However, with unencrypted 7z files it still extracts the whole thing

@ciriousjoker commented on GitHub (Feb 5, 2017): So I'd have to fix your library? Or are you saying that my encrypted 7zip file is broken? By the way, no matter what 7zip file I use (encrypted or not doesn't matter), I get this weird thing in the locals tab: https://gyazo.com/363d6b37b9dd0ff79df69d602d04fa52 Not sure if it has something to do with this error, but it always throws that error. However, with unencrypted 7z files it still extracts the whole thing
Author
Owner

@adamhathcock commented on GitHub (Feb 5, 2017):

I have a feeling encrypted 7zip just isn't supported. I don't recall putting that in the supported formats matrix

@adamhathcock commented on GitHub (Feb 5, 2017): I have a feeling encrypted 7zip just isn't supported. I don't recall putting that in the supported formats matrix
Author
Owner

@ciriousjoker commented on GitHub (Feb 5, 2017):

Ye, I just assumed that encrypted 7zips wouldn't make a difference to the 7z.dll ...

Anyway, I "fixed" it now by encrypting the final 7z with AES. For my purposes that's acceptable

@ciriousjoker commented on GitHub (Feb 5, 2017): Ye, I just assumed that encrypted 7zips wouldn't make a difference to the 7z.dll ... Anyway, I "fixed" it now by encrypting the final 7z with AES. For my purposes that's acceptable
Author
Owner

@adamhathcock commented on GitHub (Feb 5, 2017):

This code doesn't used the 7z dll. That's why he behavior is different than other libraries as others do use the native dll.

@adamhathcock commented on GitHub (Feb 5, 2017): This code doesn't used the 7z dll. That's why he behavior is different than other libraries as others do use the native dll.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#155