Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
olegfeferman opened this issue Aug 25, 2023 · 6 comments

Comments

@olegfeferman
Copy link

olegfeferman commented 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.

@olegfeferman olegfeferman changed the title IArchiveEntryExtensions WriteTo does not write to stream in 0.33 IArchiveEntryExtensions WriteTo does not write to stream in 0.33 (RarArchive) Aug 25, 2023
@Erior
Copy link
Contributor

Erior commented Sep 4, 2023

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

@olegfeferman
Copy link
Author

It reports correct size in bytes of that entry

@Erior
Copy link
Contributor

Erior commented 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

@olegfeferman
Copy link
Author

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 olegfeferman changed the title IArchiveEntryExtensions WriteTo does not write to stream in 0.33 (RarArchive) Rar5: IArchiveEntryExtensions WriteTo does not write to stream in 0.33 (RarArchive) Sep 5, 2023
@adamhathcock
Copy link
Owner

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

Dup of #372

@olegfeferman
Copy link
Author

I didn't know. Thank you!

@olegfeferman olegfeferman closed this as not planned Won't fix, can't repro, duplicate, stale Sep 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants