IndexOutOfRangeException #567

Open
opened 2026-01-29 22:13:53 +00:00 by claunia · 3 comments
Owner

Originally created by @fmscole on GitHub (May 18, 2023).

version 0.33
code :

using System;
using System.IO;
using System.Security.Cryptography;
using System.Text;
using SharpCompress.Archives;
using SharpCompress.Archives.Rar;
using SharpCompress.Factories;
using SharpCompress.Readers;

namespace RarMD5Calculator
{
    class Program
    {
        static void Main(string[] args)
        {
            string rarFilePath = "E:\\教案资料2库\\新建文件夹\\高中数学特级教师王新敞精品教案大全.rar";
            RarFactory factory = new RarFactory();
            SharpCompress.Readers.ReaderOptions options = new SharpCompress.Readers.ReaderOptions();
            options.ArchiveEncoding.Default = Encoding.GetEncoding("GBK");
            options.Password = "www.fjmath.com";
            using (Stream stream = File.OpenRead(rarFilePath))
            using (IArchive archive = factory.Open(stream, options))
            {
                foreach (var entry in archive.Entries)
                {
                    if (!entry.IsDirectory)
                    {
                        using (Stream entryStream = entry.OpenEntryStream())
                        {
                            string md5 = CalculateMD5(entryStream);
                            Console.WriteLine($"{entry.Key}: {md5}");
                        }
                    }
                }
            }
        }

        public static string CalculateMD5(Stream stream)
        {
            using (var md5 = MD5.Create())
            {
                byte[] hash = md5.ComputeHash(stream);
                return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant();
            }
        }
    }
}

image

image

Originally created by @fmscole on GitHub (May 18, 2023). version 0.33 code : ``` using System; using System.IO; using System.Security.Cryptography; using System.Text; using SharpCompress.Archives; using SharpCompress.Archives.Rar; using SharpCompress.Factories; using SharpCompress.Readers; namespace RarMD5Calculator { class Program { static void Main(string[] args) { string rarFilePath = "E:\\教案资料2库\\新建文件夹\\高中数学特级教师王新敞精品教案大全.rar"; RarFactory factory = new RarFactory(); SharpCompress.Readers.ReaderOptions options = new SharpCompress.Readers.ReaderOptions(); options.ArchiveEncoding.Default = Encoding.GetEncoding("GBK"); options.Password = "www.fjmath.com"; using (Stream stream = File.OpenRead(rarFilePath)) using (IArchive archive = factory.Open(stream, options)) { foreach (var entry in archive.Entries) { if (!entry.IsDirectory) { using (Stream entryStream = entry.OpenEntryStream()) { string md5 = CalculateMD5(entryStream); Console.WriteLine($"{entry.Key}: {md5}"); } } } } } public static string CalculateMD5(Stream stream) { using (var md5 = MD5.Create()) { byte[] hash = md5.ComputeHash(stream); return BitConverter.ToString(hash).Replace("-", "").ToLowerInvariant(); } } } } ``` ![image](https://github.com/adamhathcock/sharpcompress/assets/8135902/a094f88f-7e37-4c00-8bf3-db55c58c359d) ![image](https://github.com/adamhathcock/sharpcompress/assets/8135902/1ad91838-fcc9-419f-8707-d8336dcfe7ea)
Author
Owner

@adamhathcock commented on GitHub (May 19, 2023):

Either your password is wrong, encoding is wrong or bad RAR

@adamhathcock commented on GitHub (May 19, 2023): Either your password is wrong, encoding is wrong or bad RAR
Author
Owner

@fmscole commented on GitHub (May 22, 2023):

@adamhathcock When I use WinRAR to extract, there is no problem, so there is no issue with the password or file. The occurrence of this error is accidental, as it happens only halfway through the reading process and the password must be correct.

@fmscole commented on GitHub (May 22, 2023): @adamhathcock When I use WinRAR to extract, there is no problem, so there is no issue with the password or file. The occurrence of this error is accidental, as it happens only halfway through the reading process and the password must be correct.
Author
Owner

@Erior commented on GitHub (Jun 4, 2023):

we might take a look if we have a file to verify the claim

@Erior commented on GitHub (Jun 4, 2023): we might take a look if we have a file to verify the claim
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#567