NUnrar.InvalidRarFormatException: 'Invalid Rar Header: 134' #336

Closed
opened 2026-01-29 22:10:20 +00:00 by claunia · 5 comments
Owner

Originally created by @martinsolovey on GitHub (Dec 12, 2018).

Hi,

First of all, thank you for such a complete library, I hope I can sort out here the issues and take advantage of it.

So I have a winRar made .rar file, perfectly fine which I can decompress with winRar without problems.

The code that I am running is the following:
RarArchive file = RarArchive.Open(_fileName.FullName);
foreach (RarArchiveEntry rarFile in file.Entries)
{
string path = Path.Combine(_pathToExtract, rarFile.FilePath);
using (FileStream output = File.OpenWrite(path))
rarFile.WriteTo(output);
}

But when it tries to access the Entires, I get that invalid header exception, I am actually lost on how to move on, because the file is .rar legit.

Hope you can help me down here.

Thanks!

Originally created by @martinsolovey on GitHub (Dec 12, 2018). Hi, First of all, thank you for such a complete library, I hope I can sort out here the issues and take advantage of it. So I have a winRar made .rar file, perfectly fine which I can decompress with winRar without problems. The code that I am running is the following: RarArchive file = RarArchive.Open(_fileName.FullName); foreach (RarArchiveEntry rarFile in file.Entries) { string path = Path.Combine(_pathToExtract, rarFile.FilePath); using (FileStream output = File.OpenWrite(path)) rarFile.WriteTo(output); } But when it tries to access the Entires, I get that invalid header exception, I am actually lost on how to move on, because the file is .rar legit. Hope you can help me down here. Thanks!
Author
Owner

@adamhathcock commented on GitHub (Dec 13, 2018):

Are you actually using NUnrar still? Please use Sharpcompress instead. Usage is similar.

It could be a RAR5 file format which NUnrar definitely doesn't know how to deal with.

@adamhathcock commented on GitHub (Dec 13, 2018): Are you actually using NUnrar still? Please use Sharpcompress instead. Usage is similar. It could be a RAR5 file format which NUnrar definitely doesn't know how to deal with.
Author
Owner

@martinsolovey commented on GitHub (Dec 13, 2018):

Hi Adam,

Thanks again for your time, hope I can get this working.
Sorry, I didn't mean to post the Nunrar, I just miss-copied probably, been the whole day trying out any api that I found out there, none has worked so far. I also tried with SharpCompress, I'll post down here my SharpCompress code.

Screenshot from Gyazo

var dir = new DirectoryInfo(_pathToExtract);

        //open Archive
        var archive = ArchiveFactory.Open(_fileName);
        //sort the entries
        var sortedEntries = archive.Entries.OrderBy(x => x.Key.Length);
        foreach (var entry in sortedEntries)
        {
            if (entry.IsDirectory && !Directory.Exists(dir.FullName + "\\" + entry.Key))
            {
                //create sub-directory
                dir.CreateSubdirectory(entry.Key);
            }
            else if (!File.Exists(dir.FullName + "\\" + entry.Key))
            {
                //extract the file
                //QUESTION: Is this the correct line in order to extract the file ?
                entry.WriteTo(File.Create(dir.FullName + "\\" + entry.Key));
            }
        }

The exception I get is the following:
System.NotSupportedException: 'Unknown header: 561144146'

It is highly possible that my winrar version is just not supported, is that possible? how can I get my winrar to generate a sharpcompress supported rar output?

Thanks again man, I really appreciate you taking the time to check this out and respond.

@martinsolovey commented on GitHub (Dec 13, 2018): Hi Adam, Thanks again for your time, hope I can get this working. Sorry, I didn't mean to post the Nunrar, I just miss-copied probably, been the whole day trying out any api that I found out there, none has worked so far. I also tried with SharpCompress, I'll post down here my SharpCompress code. [![Screenshot from Gyazo](https://gyazo.com/9ffe5006daf02149f60b05cceb38cbe9/raw)](https://gyazo.com/9ffe5006daf02149f60b05cceb38cbe9) var dir = new DirectoryInfo(_pathToExtract); //open Archive var archive = ArchiveFactory.Open(_fileName); //sort the entries var sortedEntries = archive.Entries.OrderBy(x => x.Key.Length); foreach (var entry in sortedEntries) { if (entry.IsDirectory && !Directory.Exists(dir.FullName + "\\" + entry.Key)) { //create sub-directory dir.CreateSubdirectory(entry.Key); } else if (!File.Exists(dir.FullName + "\\" + entry.Key)) { //extract the file //QUESTION: Is this the correct line in order to extract the file ? entry.WriteTo(File.Create(dir.FullName + "\\" + entry.Key)); } } The exception I get is the following: System.NotSupportedException: 'Unknown header: 561144146' It is highly possible that my winrar version is just not supported, is that possible? how can I get my winrar to generate a sharpcompress supported rar output? Thanks again man, I really appreciate you taking the time to check this out and respond.
Author
Owner

@adamhathcock commented on GitHub (Dec 13, 2018):

What version are you using? That exception doesn't seem to exist in the code base anymore. The full stack trace might help too

@adamhathcock commented on GitHub (Dec 13, 2018): What version are you using? That exception doesn't seem to exist in the code base anymore. The full stack trace might help too
Author
Owner

@martinsolovey commented on GitHub (Dec 13, 2018):

I just did some version double check, and on a phantom context it now works lol.

I am now fighting a bit with extracting onto a path where files/directories should be replaced.
Basically the behavior I need is a normal ExtractAll with override (for both directories and files) do you happen to have any additional class there that might work like that?

I tried ExtractAllEntries() from Archive, but it doesn't seem to do the trick.

@martinsolovey commented on GitHub (Dec 13, 2018): I just did some version double check, and on a phantom context it now works lol. I am now fighting a bit with extracting onto a path where files/directories should be replaced. Basically the behavior I need is a normal ExtractAll with override (for both directories and files) do you happen to have any additional class there that might work like that? I tried ExtractAllEntries() from Archive, but it doesn't seem to do the trick.
Author
Owner

@martinsolovey commented on GitHub (Dec 13, 2018):

Actually Adam, I just made it work under my specs, I share here my wrapper so you can include it in your api if you want.

Thanks a lot for your good will!

public class Decompresser
    {
        public void Decompress(DirectoryInfo targetDirectory, FileInfo file)
        {
            using (var archive = ArchiveFactory.Open(file))
            {
                foreach (var entry in archive.Entries.OrderBy(x => x.IsDirectory))
                {
                    if (entry.IsDirectory)
                        ProcessDirectory(targetDirectory, entry);
                    else
                        ProcessFile(targetDirectory, entry);
                }
            }
        }

        private void ProcessFile(FileSystemInfo dir, IArchiveEntry entry)
        {
            entry.WriteToFile(GetTargetPath(dir, entry), new ExtractionOptions() { Overwrite = true });
        }

        private void ProcessDirectory(DirectoryInfo dir, IArchiveEntry entry)
        {
            if (!Directory.Exists(GetTargetPath(dir, entry)))
                dir.CreateSubdirectory(entry.Key);
        }

        private string GetTargetPath(FileSystemInfo dir, IArchiveEntry entry)
        {
            return dir.FullName + "\\" + entry.Key;
        }
    }
@martinsolovey commented on GitHub (Dec 13, 2018): Actually Adam, I just made it work under my specs, I share here my wrapper so you can include it in your api if you want. Thanks a lot for your good will! ``` public class Decompresser { public void Decompress(DirectoryInfo targetDirectory, FileInfo file) { using (var archive = ArchiveFactory.Open(file)) { foreach (var entry in archive.Entries.OrderBy(x => x.IsDirectory)) { if (entry.IsDirectory) ProcessDirectory(targetDirectory, entry); else ProcessFile(targetDirectory, entry); } } } private void ProcessFile(FileSystemInfo dir, IArchiveEntry entry) { entry.WriteToFile(GetTargetPath(dir, entry), new ExtractionOptions() { Overwrite = true }); } private void ProcessDirectory(DirectoryInfo dir, IArchiveEntry entry) { if (!Directory.Exists(GetTargetPath(dir, entry))) dir.CreateSubdirectory(entry.Key); } private string GetTargetPath(FileSystemInfo dir, IArchiveEntry entry) { return dir.FullName + "\\" + entry.Key; } } ```
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#336