adamhathcock / sharpcompress

SharpCompress is a fully managed C# library to deal with many compression types and formats.
MIT License
2.24k stars 480 forks source link

7-zip 23.01 #748

Open Quetzalcoatl2435 opened 1 year ago

Quetzalcoatl2435 commented 1 year ago

I've recently updated 7-zip to v23.01 and files compressed with it can be extracted properly on linux-x64, but fails on linux-arm (e.g. Raspberry Pi) with unsupported method error message.

Reverted back to 7-zip v22.01 and everything works properly again.

Not a very big deal, but would be nice to get 7-zip 23.01 support, 'cause every other lib I've tried only supports Windows, so this library is really a life saver.

Thanks!

adamhathcock commented 1 year ago

Please give me a stacktrace. ARM isn't somehing I explicity test.

Quetzalcoatl2435 commented 1 year ago
Specified method is not supported.
   at SharpCompress.Compressors.LZMA.DecoderRegistry.CreateDecoderStream(CMethodId , Stream[] , Byte[] , IPasswordProvider , Int64 )
   at SharpCompress.Compressors.LZMA.DecoderStreamHelper.CreateDecoderStream(Stream[] , Int64[] , Stream[] , CFolder , Int32 , IPasswordProvider )
   at SharpCompress.Compressors.LZMA.DecoderStreamHelper.CreateDecoderStream(Stream , Int64 , Int64[] , CFolder , IPasswordProvider )
   at SharpCompress.Common.SevenZip.ArchiveDatabase.GetFolderStream(Stream , CFolder , IPasswordProvider )
   at SharpCompress.Common.SevenZip.SevenZipFilePart.GetCompressedStream()
   at SharpCompress.Archives.SevenZip.SevenZipArchiveEntry.OpenEntryStream()
   at SharpCompress.Archives.IArchiveEntryExtensions.WriteTo(IArchiveEntry , Stream )
   at SharpCompress.Archives.IArchiveEntryExtensions.<>c__DisplayClass2_0.<WriteToFile>b__0(String , FileMode )
   at SharpCompress.Common.ExtractionMethods.WriteEntryToFile(IEntry , String , ExtractionOptions , Action`2 )
   at SharpCompress.Archives.IArchiveEntryExtensions.WriteToFile(IArchiveEntry , String , ExtractionOptions )
   at SharpCompress.Common.ExtractionMethods.WriteEntryToDirectory(IEntry , String , ExtractionOptions , Action`2 )
   at Program.<Main>$(String[] args)
adamhathcock commented 1 year ago

There must be a decoder stream ID we don't have any code for that's being used here.

I would debug and see what's different. Not sure why the older works as there was additive changes in the registry but nothing ARM specific

Quetzalcoatl2435 commented 1 year ago

Did some more testing and now I get the same error in linux-x64. I didn't catch it before because I tested different files on x64/ARM. This time I tested the same files and got the same error. Weird thing is that it works for some files and not for others. Same compression settings for all files. The only difference I can see so far between the files where extraction fails/succeeds is size. Files < 10 MB fail, files > 10 MB are OK.

using SharpCompress.Archives;
using SharpCompress.Archives.SevenZip;
using SharpCompress.Common;

try
{
    if (args.Length == 0)
    {
        Console.WriteLine("No file specified.");
        return;
    }

    Console.WriteLine("Extracting archive...");
    using var archive = SevenZipArchive.Open(args[0]);
    foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory))
    {
        Console.WriteLine(entry.Key);
        entry.WriteToDirectory(".", new ExtractionOptions()
        {
            ExtractFullPath = true,
            Overwrite = true,
            PreserveFileTime = true
        });
    }
    Console.WriteLine("Done!");
}
catch (Exception ex)
{
    File.AppendAllText("Debug.log", ex.Message + Environment.NewLine + ex.StackTrace + Environment.NewLine);
}

Test files: Test.zip

Results: libHarfBuzzSharp.7z -> exception libmongocrypt.7z -> OK libSkiaSharp.7z -> exception libSystem.IO.Ports.Native.7z -> exception