Extracting file from password protected RAR creates 0 bytes file #537

Open
opened 2026-01-29 22:13:26 +00:00 by claunia · 1 comment
Owner

Originally created by @Sonic3R on GitHub (Sep 12, 2022).

Hi

using (RarArchive archive = RarArchive.Open(rarFile, new SharpCompress.Readers.ReaderOptions { Password = pass }))
{
   foreach (var entry in archive.Entries) {
        entry.WriteToFile(tempFile, new SharpCompress.Common.ExtractionOptions { Overwrite = true });
   }
}

Even I supplied password, it does not extract any file and I have 0 byte file. I tested with 7-zip file manager to see if password is good, and it is good.

Edit:

I tried also

RarReader reader = RarReader.Open(entry.OpenEntryStream());
using (var fs = File.OpenWrite(temp))
{
    reader.WriteEntryTo(fs);
}

And I got exception: System.NullReferenceException: Object reference not set to an instance of an object.

And stacktrace:

   at SharpCompress.Readers.AbstractReader`2.get_Entry()
   at SharpCompress.Readers.Rar.RarReader.CreateFilePartEnumerableForCurrentEntry()
   at SharpCompress.Readers.Rar.RarReader.GetEntryStream()
   at SharpCompress.Readers.AbstractReader`2.OpenEntryStream()
   at SharpCompress.Readers.AbstractReader`2.Write(Stream writeStream)
   at SharpCompress.Readers.AbstractReader`2.WriteEntryTo(Stream writableStream)
Originally created by @Sonic3R on GitHub (Sep 12, 2022). Hi ``` using (RarArchive archive = RarArchive.Open(rarFile, new SharpCompress.Readers.ReaderOptions { Password = pass })) { foreach (var entry in archive.Entries) { entry.WriteToFile(tempFile, new SharpCompress.Common.ExtractionOptions { Overwrite = true }); } } ``` Even I supplied password, it does not extract any file and I have 0 byte file. I tested with 7-zip file manager to see if password is good, and it is good. Edit: I tried also ``` RarReader reader = RarReader.Open(entry.OpenEntryStream()); using (var fs = File.OpenWrite(temp)) { reader.WriteEntryTo(fs); } ``` And I got exception: System.NullReferenceException: `Object reference not set to an instance of an object.` And stacktrace: ``` at SharpCompress.Readers.AbstractReader`2.get_Entry() at SharpCompress.Readers.Rar.RarReader.CreateFilePartEnumerableForCurrentEntry() at SharpCompress.Readers.Rar.RarReader.GetEntryStream() at SharpCompress.Readers.AbstractReader`2.OpenEntryStream() at SharpCompress.Readers.AbstractReader`2.Write(Stream writeStream) at SharpCompress.Readers.AbstractReader`2.WriteEntryTo(Stream writableStream) ```
claunia added the enhancementup for grabs labels 2026-01-29 22:13:26 +00:00
Author
Owner

@adamhathcock commented on GitHub (Sep 14, 2022):

This might be because we don't support RAR 5.0 decryption yet.

Related https://github.com/adamhathcock/sharpcompress/issues/631

@adamhathcock commented on GitHub (Sep 14, 2022): This might be because we don't support RAR 5.0 decryption yet. Related https://github.com/adamhathcock/sharpcompress/issues/631
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#537