SevenZipSharp
SevenZipSharp copied to clipboard
bugfix/dispose-stream-for-corrupted-archive-check
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:
- zip any file/folder using the .7z format.
- open the 7z file in notepad and remove a random chunk of lines/data.
- The following code will throw an exception:
using (var extractor = new SevenZipExtractor(@"TestData\CorruptedArchive.7z"))
{
if (!extractor.Check())
{
}
}
File.OpenWrite(@"TestData\CorruptedArchive.7z");
Do you have a .dll with this bugfix?