【问题标题】:Why I Received Data Error Exception on 7-zip SDK? winrar 5 decompressing为什么我在 7-zip SDK 上收到数据错误异常? winrar 5 解压
【发布时间】:2021-03-26 15:03:27
【问题描述】:

我附加了特殊的 winrar 存档,其中 sdk 给了我错误。拜托,你能帮帮我吗?

archive for simulate bug and test

调用示例:

 MemoryStream inputMemoryStream = new MemoryStream();
 string archiveFilePath = @"c:\winrar.rar";
 File.OpenRead(archiveFilePath).CopyTo(inputMemoryStream);
 var bb = ExtractBytes(inputMemoryStream.ToArray());



private byte[] ExtractBytes(byte[] data)
{
        using (var inStream = new MemoryStream(data))
        {
            var decoder = new SevenZip.Compression.LZMA.Decoder();
            inStream.Seek(0, 0);
            using (var outStream = new MemoryStream())
            {
                long outSize;
                decoder.SetDecoderProperties(GetLzmaProperties(inStream, out outSize));
                decoder.Code(inStream, outStream, inStream.Length - inStream.Position, outSize, null);
                return outStream.ToArray();
            }
        }
 }
    
     private byte[] GetLzmaProperties(Stream inStream, out long outSize)
    {
        var lzmAproperties = new byte[5];
        if (inStream.Read(lzmAproperties, 0, 5) != 5)
        {
            throw new Exception("LzmaException");
        }
        outSize = 0;
        for (int i = 0; i < 8; i++)
        {
            int b = inStream.ReadByte();
            if (b < 0)
            {
                throw new Exception("LzmaException");
            }
            outSize |= ((long)(byte)b) << (i << 3);
        }
        return lzmAproperties;
    }

调用代码函数时发生异常:

decoder.Code(inStream, outStream, inStream.Length - inStream.Position, outSize, null);
            

https://www.7-zip.org/sdk.html 19.00版

异常调试详情

期望的行为:7zip 支持 winrar,那么我的代码出了什么问题?

存档格式信息:https://superuser.com/questions/770370/what-is-the-difference-between-rar-and-rar5-compression

【问题讨论】:

    标签: c# sdk 7zip rar winrar


    【解决方案1】:

    LZMA SDK 不能用于提取 RAR 压缩包:

    • RAR 没有使用 LZMA 作为压缩算法,并且 LZMA SDK 不支持 RAR
    • 7-Zip 和 LZMA SDK 不是一回事
    • 7-Zip 使用来自 RARLAB 的 unrar 代码,该代码是专有的

    【讨论】:

      猜你喜欢
      • 2013-07-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-06-04
      相关资源
      最近更新 更多