Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

bugfix/dispose-stream-for-corrupted-archive-check #178

Open
wants to merge 3 commits into
base: dev
Choose a base branch
from

Conversation

RAORelewise
Copy link

@RAORelewise RAORelewise commented Jan 11, 2023

Hi there,

While implementing an archive backup system using this library and doing an intregity check on a purposely corrupted file, I was no longer able to access the file until the next GC.

A quick browse of the code, I noticed that the public bool Check() method catches all exceptions and just returns false, but since streams are shared between several method, there appears to be some sort of state regarding when the stream can be closed. And an exception bubbling from the InitArchiveFileData(diseposeStream: false); method, would prevent the stream from being closed.

This change ensures the stream can be closed if an exception is thrown, however, maybe the "correct" solution is to just change the disposeStream parameter to true in the InitArchiveFileData method.

Steps to reproduce:

  1. zip any file/folder using the .7z format.
  2. open the 7z file in notepad and remove a random chunk of lines/data.
  3. The following code will throw an exception:
            using (var extractor = new SevenZipExtractor(@"TestData\CorruptedArchive.7z"))
            {
                if (!extractor.Check())
                {
                    
                }
            }
            
            File.OpenWrite(@"TestData\CorruptedArchive.7z");

@ionutradu252
Copy link

Do you have a .dll with this bugfix?

This commit is mainly to trigger a new check against the new checks.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants