Rar5: IArchiveEntryExtensions WriteTo does not write to stream in 0.33 (RarArchive) #582

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

Originally created by @olegfeferman on GitHub (Aug 25, 2023).

Hello,

I am trying to write a piece of code that verifies if user entered a correct password in case archive was password protected like this:

        using (var archive = RarArchive.Open(archiveFile, new ReaderOptions() { Password = pass }))
        {
            var entry = archive.Entries.FirstOrDefault(e => !e.IsDirectory);
            
            using (var stream = new MemoryStream( (int) entry.Size))
            {                    
                entry.WriteTo(stream);                                        
                if (stream.Length == 0)
                {
                    ShowMessage("You have entered incorrect password.");
                }
            }
        }

Problem is stream is always zero. Either it is a bug or I am doing something wrong.

Originally created by @olegfeferman on GitHub (Aug 25, 2023). Hello, I am trying to write a piece of code that verifies if user entered a correct password in case archive was password protected like this: using (var archive = RarArchive.Open(archiveFile, new ReaderOptions() { Password = pass })) { var entry = archive.Entries.FirstOrDefault(e => !e.IsDirectory); using (var stream = new MemoryStream( (int) entry.Size)) { entry.WriteTo(stream); if (stream.Length == 0) { ShowMessage("You have entered incorrect password."); } } } Problem is stream is always zero. Either it is a bug or I am doing something wrong.
claunia added the duplicate label 2026-01-29 22:14:07 +00:00
Author
Owner

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

What does entry.Size say for the difference scenarios you test?

@Erior commented on GitHub (Sep 4, 2023): What does entry.Size say for the difference scenarios you test?
Author
Owner

@olegfeferman commented on GitHub (Sep 4, 2023):

It reports correct size in bytes of that entry

@olegfeferman commented on GitHub (Sep 4, 2023): It reports correct size in bytes of that entry
Author
Owner

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

I don't think you actually know if the password is correct until you try to decompress, that would give you a size, however it would be the wrong size / CRC, comparing the result with entry.Size would make more sense.
Btw, when I try this with encrypted header info, it throw an exception, you might need to catch that if you have such files.

I tested your code snippet as a test with the archive "Rar.encrypted_filesOnly.rar".
At least with that encrypted test file I got stream.Length

@Erior commented on GitHub (Sep 4, 2023): I don't think you actually know if the password is correct until you try to decompress, that would give you a size, however it would be the wrong size / CRC, comparing the result with entry.Size would make more sense. Btw, when I try this with encrypted header info, it throw an exception, you might need to catch that if you have such files. I tested your code snippet as a test with the archive "Rar.encrypted_filesOnly.rar". At least with that encrypted test file I got stream.Length
Author
Owner

@olegfeferman commented on GitHub (Sep 5, 2023):

Thank you for the feedback. When I test with Rar.encrypted_filesAndHeader.rar or Rar.encrypted_filesOnly.rar it works OK (in first case I get exception in second stream.Length is greater than 0).
What I did not realize before you sent your message is that I am only having problem with Rar5.encrypted_filesAndHeader.rar and Rar5.encrypted_filesOnly.rar. Actually before I was just testing with a test archive that I created with latest version of Winrar (6.23).

@olegfeferman commented on GitHub (Sep 5, 2023): Thank you for the feedback. When I test with Rar.encrypted_filesAndHeader.rar or Rar.encrypted_filesOnly.rar it works OK (in first case I get exception in second stream.Length is greater than 0). What I did not realize before you sent your message is that I am only having problem with Rar5.encrypted_filesAndHeader.rar and Rar5.encrypted_filesOnly.rar. Actually before I was just testing with a test archive that I created with latest version of Winrar (6.23).
Author
Owner

@adamhathcock commented on GitHub (Sep 7, 2023):

RAR5 decryption is a known TODO: https://github.com/adamhathcock/sharpcompress#todos-always-lots

Dup of https://github.com/adamhathcock/sharpcompress/issues/372

@adamhathcock commented on GitHub (Sep 7, 2023): RAR5 decryption is a known TODO: https://github.com/adamhathcock/sharpcompress#todos-always-lots Dup of https://github.com/adamhathcock/sharpcompress/issues/372
Author
Owner

@olegfeferman commented on GitHub (Sep 7, 2023):

I didn't know. Thank you!

@olegfeferman commented on GitHub (Sep 7, 2023): I didn't know. Thank you!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#582