Extraction failes on freshly created zip, rar with winrar. #311

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

Originally created by @naice on GitHub (Jul 3, 2018).

When I extract freshly generated archives (zip, rar) All I get are exceptions.

For the rar archive I get the RarCrcStream "file crc missmatch" exception when opening the compressed stream via OpenEntryStream() and call the Read from the stream.

For the zip archive I get an "Unknown header: 425723911" after extracting the first file and move on to next entry with MoveToNextEntry().

Do I missunderstand how this works, or are these bugs? I am using version 0.21.1.0

using (var archiveStream = File.OpenRead(_archiveFile))
{
    using (var reader = SharpCompress.Readers.ReaderFactory.Open(archiveStream, new SharpCompress.Readers.ReaderOptions() { Password = pwd }))
    {
        long fileMaximum = 0, fileValue = 0, lastCompressedBytesRead = 0;
        if (_extractionProgressReport != null)
        {
            reader.CompressedBytesRead += (_, args) => {
                lastCompressedBytesRead = args.CompressedBytesRead;
                _extractionProgressReport?.ReportProgress(false, archiveStream.Length, args.CompressedBytesRead, fileMaximum, fileValue, currentFile);
            };
        }

        while (reader.MoveToNextEntry())
        {
            var entry = reader.Entry;

            if (entry.IsDirectory) continue;

            fileMaximum = entry.Size;
            fileValue = 0;
            currentFile = Path.Combine(_destinationDir, entry.Key);
            currentDir = Path.GetDirectoryName(currentFile);

            if (cancellationToken.IsCancellationRequested) break;

            if (!Directory.Exists(currentDir))
                Directory.CreateDirectory(currentDir);

            using (var dest = File.Create(currentFile))
            {
                using (var src = reader.OpenEntryStream())
                {
                    const int bufferSize = 1024 * 4;
                    byte[] buffer = new byte[bufferSize];
                    int bytesRead = 0;

                    while ((bytesRead = src.Read(buffer, 0, bufferSize)) > 0)
                    {
                        dest.Write(buffer, 0, bytesRead);
                        fileValue += bytesRead;

                        if (cancellationToken.IsCancellationRequested) break;
                        _extractionProgressReport?.ReportProgress(false, archiveStream.Length, lastCompressedBytesRead, fileMaximum, fileValue, currentFile);
                    }
                }
            }
        }
    }
}

Originally created by @naice on GitHub (Jul 3, 2018). When I extract freshly generated archives (zip, rar) All I get are exceptions. For the rar archive I get the RarCrcStream "file crc missmatch" exception when opening the compressed stream via OpenEntryStream() and call the Read from the stream. For the zip archive I get an "Unknown header: 425723911" after extracting the first file and move on to next entry with MoveToNextEntry(). Do I missunderstand how this works, or are these bugs? I am using version 0.21.1.0 ``` using (var archiveStream = File.OpenRead(_archiveFile)) { using (var reader = SharpCompress.Readers.ReaderFactory.Open(archiveStream, new SharpCompress.Readers.ReaderOptions() { Password = pwd })) { long fileMaximum = 0, fileValue = 0, lastCompressedBytesRead = 0; if (_extractionProgressReport != null) { reader.CompressedBytesRead += (_, args) => { lastCompressedBytesRead = args.CompressedBytesRead; _extractionProgressReport?.ReportProgress(false, archiveStream.Length, args.CompressedBytesRead, fileMaximum, fileValue, currentFile); }; } while (reader.MoveToNextEntry()) { var entry = reader.Entry; if (entry.IsDirectory) continue; fileMaximum = entry.Size; fileValue = 0; currentFile = Path.Combine(_destinationDir, entry.Key); currentDir = Path.GetDirectoryName(currentFile); if (cancellationToken.IsCancellationRequested) break; if (!Directory.Exists(currentDir)) Directory.CreateDirectory(currentDir); using (var dest = File.Create(currentFile)) { using (var src = reader.OpenEntryStream()) { const int bufferSize = 1024 * 4; byte[] buffer = new byte[bufferSize]; int bytesRead = 0; while ((bytesRead = src.Read(buffer, 0, bufferSize)) > 0) { dest.Write(buffer, 0, bytesRead); fileValue += bytesRead; if (cancellationToken.IsCancellationRequested) break; _extractionProgressReport?.ReportProgress(false, archiveStream.Length, lastCompressedBytesRead, fileMaximum, fileValue, currentFile); } } } } } } ```
Author
Owner

@adamhathcock commented on GitHub (Jul 3, 2018):

Try using some of the built-in extension methods for extracting to see if you get the same issue. https://github.com/adamhathcock/sharpcompress/blob/master/USAGE.md#extract-all-files-from-a-rar-file-to-a-directory-using-rararchive

@adamhathcock commented on GitHub (Jul 3, 2018): Try using some of the built-in extension methods for extracting to see if you get the same issue. https://github.com/adamhathcock/sharpcompress/blob/master/USAGE.md#extract-all-files-from-a-rar-file-to-a-directory-using-rararchive
Author
Owner

@naice commented on GitHub (Jul 3, 2018):

That would mean I loose control over writing a file, I want to be able to Pause the progress, or abort it at least via CancellationToken.... I suggest you to support at least cancellation via your extensions. Feels kinda odd to be not able to abort a large extraction -> usabillity.

EDIT: Same exceptions with the extensions.

@naice commented on GitHub (Jul 3, 2018): That would mean I loose control over writing a file, I want to be able to Pause the progress, or abort it at least via CancellationToken.... I suggest you to support at least cancellation via your extensions. Feels kinda odd to be not able to abort a large extraction -> usabillity. EDIT: Same exceptions with the extensions.
Author
Owner

@adamhathcock commented on GitHub (Jul 3, 2018):

I understand that. Just trying to make sure there's not an issue with the library.

@adamhathcock commented on GitHub (Jul 3, 2018): I understand that. Just trying to make sure there's not an issue with the library.
Author
Owner

@naice commented on GitHub (Jul 3, 2018):

That are both archives created with winrar, however the rar_archive is in that zip, file restrictions from github. Passwords are in double braces!

test_archive{{test123456}}.zip

rar_file.zip

@naice commented on GitHub (Jul 3, 2018): That are both archives created with winrar, however the rar_archive is in that zip, file restrictions from github. Passwords are in double braces! [test_archive{{test123456}}.zip](https://github.com/adamhathcock/sharpcompress/files/2158223/test_archive.test123456.zip) [rar_file.zip](https://github.com/adamhathcock/sharpcompress/files/2158230/rar_file.zip)
Author
Owner

@adamhathcock commented on GitHub (Jul 3, 2018):

I'm not going to test it. I was asking you to test extracting with the provided methods to prove it's an issue with the library or just your usage.

@adamhathcock commented on GitHub (Jul 3, 2018): I'm not going to test it. I was asking you to test extracting with the provided methods to prove it's an issue with the library or just your usage.
Author
Owner

@naice commented on GitHub (Jul 3, 2018):

I've already written "Same exceptions with the extensions". Also CompressedBytesRead seems to be never called.

@naice commented on GitHub (Jul 3, 2018): I've already written "Same exceptions with the extensions". Also CompressedBytesRead seems to be never called.
Author
Owner

@adamhathcock commented on GitHub (Jul 3, 2018):

You edited that in. You've only provided code try things your way.

You're welcome to open a pull request and add functionality to cancel but I'm not inclined to do it for you.

@adamhathcock commented on GitHub (Jul 3, 2018): You edited that in. You've only provided code try things your way. You're welcome to open a pull request and add functionality to cancel but I'm not inclined to do it for you.
Author
Owner

@naice commented on GitHub (Jul 3, 2018):

It was just a suggestion, maybe i jump in when i got some time left, you know the deal.

                        while (reader.MoveToNextEntry())
                        {
                            var entry = reader.Entry;
                            if (entry.IsDirectory) continue;
                            
                            using (var dest = File.Create(currentFile))
                            {
                                reader.WriteEntryTo(dest);

is failing and

                        while (reader.MoveToNextEntry())
                        {
                            var entry = reader.Entry;

                            if (entry.IsDirectory) continue;

                            reader.WriteEntryToDirectory(_destinationDir, new ExtractionOptions() { ExtractFullPath = true, Overwrite = true });

also. With the exact same exceptions.

@naice commented on GitHub (Jul 3, 2018): It was just a suggestion, maybe i jump in when i got some time left, you know the deal. ``` while (reader.MoveToNextEntry()) { var entry = reader.Entry; if (entry.IsDirectory) continue; using (var dest = File.Create(currentFile)) { reader.WriteEntryTo(dest); ``` is failing and ``` while (reader.MoveToNextEntry()) { var entry = reader.Entry; if (entry.IsDirectory) continue; reader.WriteEntryToDirectory(_destinationDir, new ExtractionOptions() { ExtractFullPath = true, Overwrite = true }); ``` also. With the exact same exceptions.
Author
Owner

@adamhathcock commented on GitHub (Jul 3, 2018):

The zip works for me using the Archive API but not the Reader API. The RAR doesn't work for me in the Reader API and gives me zero byte files in the Archive API

I'm guessing it doesn't like the password for the RAR but I'll look closer. I don't like that the zip works in one case but doesn't in the other. It must be something to do with using the zip dictionary vs not.

@adamhathcock commented on GitHub (Jul 3, 2018): The zip works for me using the Archive API but not the Reader API. The RAR doesn't work for me in the Reader API and gives me zero byte files in the Archive API I'm guessing it doesn't like the password for the RAR but I'll look closer. I don't like that the zip works in one case but doesn't in the other. It must be something to do with using the zip dictionary vs not.
Author
Owner

@naice commented on GitHub (Jul 3, 2018):

Well true, i have just tested it with the reader API.

@naice commented on GitHub (Jul 3, 2018): Well true, i have just tested it with the reader API.
Author
Owner

@adamhathcock commented on GitHub (Jul 3, 2018):

The zip file is erroring because it's Encrypted and has a Post Data Descriptor header. It's kind of a known issue that is broken. I'm not sure I'm going to fix it anytime soon.

@adamhathcock commented on GitHub (Jul 3, 2018): The zip file is erroring because it's Encrypted and has a Post Data Descriptor header. It's kind of a known issue that is broken. I'm not sure I'm going to fix it anytime soon.
Author
Owner

@naice commented on GitHub (Jul 3, 2018):

Ok, i will move on to another solution and discard SharpCompress then, thanks!

@naice commented on GitHub (Jul 3, 2018): Ok, i will move on to another solution and discard SharpCompress then, thanks!
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/sharpcompress#311