Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistent behavior on extracting 7zip with wrong password #811

Open
idan-weiss opened this issue Feb 29, 2024 · 0 comments
Open

Inconsistent behavior on extracting 7zip with wrong password #811

idan-weiss opened this issue Feb 29, 2024 · 0 comments

Comments

@idan-weiss
Copy link

idan-weiss commented Feb 29, 2024

Hi!

I'm trying to extract 7zip file with password.
I found out that there is inconsistent behavior when I try to use a wrong password:

For a password protected 7zip file, this is the error I get when I use the password wrong:

SharpCompress.Compressors.LZMA.DataErrorException: Data Error
   at SharpCompress.Compressors.LZMA.Decoder.Code(Int32 dictionarySize, OutWindow outWindow, Decoder rangeDecoder)
   at SharpCompress.Compressors.LZMA.LzmaStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   at SharpCompress.IO.ReadOnlySubStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   at SharpCompress.Common.EntryStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   at SharpCompress.Utility.ReadTransferBlock(Stream source, Byte[] array, Int32& count)
   at SharpCompress.Utility.TransferTo(Stream source, Stream destination, Entry entry, IReaderExtractionListener readerExtractionListener)
   at SharpCompress.Readers.AbstractReader`2.Write(Stream writeStream)
   at SharpCompress.Readers.AbstractReader`2.WriteEntryTo(Stream writableStream)

While this is the error I get when I use the password asdasd:

System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at SharpCompress.Compressors.LZMA.LZ.OutWindow.GetByte(Int32 distance)
   at SharpCompress.Compressors.LZMA.Decoder.Code(Int32 dictionarySize, OutWindow outWindow, Decoder rangeDecoder)
   at SharpCompress.Compressors.LZMA.LzmaStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   at SharpCompress.IO.ReadOnlySubStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   at SharpCompress.Common.EntryStream.Read(Byte[] buffer, Int32 offset, Int32 count)
   at SharpCompress.Utility.Skip(Stream source)
   at SharpCompress.Common.EntryStream.SkipEntry()
   at SharpCompress.Common.EntryStream.Dispose(Boolean disposing)
   at System.IO.Stream.Close()
   at SharpCompress.Readers.AbstractReader`2.Write(Stream writeStream)
   at SharpCompress.Readers.AbstractReader`2.WriteEntryTo(Stream writableStream)

The described behavior happens when I use:

        var reader = archive.ExtractAllEntries();
        while (reader.MoveToNextEntry())

But when I use this instead, both cases throw the 1st exception:

            foreach (var entry in archive.Entries) {
            ... 
                    await using var entryMemoryStream = new MemoryStream();
                    await using var entryStream = entry.OpenEntryStream();
                    await entryStream.CopyToAsync(entryMemoryStream);
            ...

I have 2 issues with that:

  • I'd expect all "wrong password" to throw the same exception
  • I'd like to have the exception class to be public. The exception above is of type SharpCompress.Compressors.LZMA.DataErrorException, which is internal, so I cannot catch it properly (I must catch non-specific Exception)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant