SevenZipSharp icon indicating copy to clipboard operation
SevenZipSharp copied to clipboard

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

Open RAORelewise opened this issue 2 years ago • 1 comments

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");

RAORelewise avatar Jan 11 '23 13:01 RAORelewise

Do you have a .dll with this bugfix?

ionutradu252 avatar Mar 15 '23 19:03 ionutradu252