adamhathcock / sharpcompress

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

Invalid Rar Header: 80 #193

Closed supershowwei closed 7 years ago

supershowwei commented 8 years ago

I have a RAR file.

It can not be decompressed.

attached is the rar file: a.zip

elgonzo commented 7 years ago

In all likelihood not a bug.

The file in the attached zip achive is a self-extracting RAR file. In other words, it is an executable file and not a 'pure' RAR archive. As such, this files does not begin with a RAR signature, but with the typical data structure of a PE32 binary executable image.

Of course, somewhere inside this file is the RAR archive data, beginning with a proper RAR archive signature (or so it should). However, by default SharpCompress expects the archive signature at the beginning of the file and does not search for it somewhere else in the file. (This default behavior does not allow SharpCompress to identify files such as self-extracting archives.)

To read such a self-extracting RAR file, you need to tell SharpCompress explicitly that it should search for the archive signature inside the file if it is not found right at the beginning of the file. This is accomplished by passing a ReaderOptions object with its ReaderOptions.LookForHeader property set to true to either the ReaderFactory.Open or ArchiveFactory.Open method; similar as in this C# example:

var arc = ArchiveFactory.Open(
    archiveFile,
    new ReaderOptions() { LookForHeader = true }
);
supershowwei commented 7 years ago

thanks for reply and explanation.

i ask the provider of rar file, the file is a exe binary file created by WinRAR.

the provider change the extension to .rar that avoid confusing.

thanks your help again.