tar file throwing "Rar signature not found" #442

Closed
opened 2026-01-29 22:12:09 +00:00 by claunia · 6 comments
Owner

Originally created by @PaulMcGuinness on GitHub (Mar 4, 2021).

I'm getting the following error on a .tar file

SharpCompress.Common.InvalidFormatException: 'Rar signature not found'

When it's not a 'rar' file at all.....

Is there an option to define the type instead of letting it decide itself?

Originally created by @PaulMcGuinness on GitHub (Mar 4, 2021). I'm getting the following error on a .tar file SharpCompress.Common.InvalidFormatException: 'Rar signature not found' When it's not a 'rar' file at all..... Is there an option to define the type instead of letting it decide itself?
Author
Owner

@adamhathcock commented on GitHub (Mar 5, 2021):

What are you using?

The Rar detection uses that exception then catches it currently so that's expected as an internal exception.

@adamhathcock commented on GitHub (Mar 5, 2021): What are you using? The Rar detection uses that exception then catches it currently so that's expected as an internal exception.
Author
Owner

@PaulMcGuinness commented on GitHub (Mar 5, 2021):

It's a TAR backup from a Cisco CUCM PABX.... Unfortunately I can't put it here as it contains customer data :-(

If I use an alternative library for this file, it works fine.

@PaulMcGuinness commented on GitHub (Mar 5, 2021): It's a TAR backup from a Cisco CUCM PABX.... Unfortunately I can't put it here as it contains customer data :-( If I use an alternative library for this file, it works fine.
Author
Owner

@adamhathcock commented on GitHub (Mar 5, 2021):

I meant, what is the code?

You can use TarReader.Open or TarArchive.Open directly if you don't like the autodetection

@adamhathcock commented on GitHub (Mar 5, 2021): I meant, what is the code? You can use TarReader.Open or TarArchive.Open directly if you don't like the autodetection
Author
Owner

@PaulMcGuinness commented on GitHub (Mar 5, 2021):

public Stream GetFile(string path)
        {
            using var archiveStream = File.OpenRead(archivePath);
            using var archiveReader = ReaderFactory.Open(archiveStream);
            while (archiveReader.MoveToNextEntry())
            {
                if (!archiveReader.Entry.IsDirectory)
                {
                    var entry_name = archiveReader.Entry.ToString();
                    if (entry_name.EndsWith(path, StringComparison.OrdinalIgnoreCase) ||
                        entry_name.ToLower() == path.ToLower())
                    {
                        var temp = new MemoryStream();
                        archiveReader.OpenEntryStream().CopyTo(temp);
                        temp.Position = 0;
                        return temp;
                    }
                }
            }
            return null;
        }
@PaulMcGuinness commented on GitHub (Mar 5, 2021): ``` public Stream GetFile(string path) { using var archiveStream = File.OpenRead(archivePath); using var archiveReader = ReaderFactory.Open(archiveStream); while (archiveReader.MoveToNextEntry()) { if (!archiveReader.Entry.IsDirectory) { var entry_name = archiveReader.Entry.ToString(); if (entry_name.EndsWith(path, StringComparison.OrdinalIgnoreCase) || entry_name.ToLower() == path.ToLower()) { var temp = new MemoryStream(); archiveReader.OpenEntryStream().CopyTo(temp); temp.Position = 0; return temp; } } } return null; } ```
Author
Owner

@adamhathcock commented on GitHub (Mar 5, 2021):

You can just change ReaderFactory to TarReader and it's fine.

Might want to be careful to dispose more stuff there. You also double check you need to buffer in memory as you can just stream the contents of entries directly to whatever.

@adamhathcock commented on GitHub (Mar 5, 2021): You can just change `ReaderFactory` to `TarReader` and it's fine. Might want to be careful to dispose more stuff there. You also double check you need to buffer in memory as you can just stream the contents of entries directly to whatever.
Author
Owner

@PaulMcGuinness commented on GitHub (Mar 5, 2021):

Many thanks

@PaulMcGuinness commented on GitHub (Mar 5, 2021): Many thanks
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#442