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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions SevenZip.Tests/SevenZip.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,9 @@
<None Include="TestData\multiple_files.7z">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="TestData\CorruptedArchive.7z">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
<None Include="TestData\multivolume.part0001.rar">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
Expand Down
16 changes: 15 additions & 1 deletion SevenZip.Tests/SevenZipExtractorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static List<TestFile> TestFiles

foreach (var file in Directory.GetFiles(Path.Combine(TestContext.CurrentContext.TestDirectory, "TestData")))
{
if (file.Contains("multi") || file.Contains("long_path"))
if (file.Contains("multi") || file.Contains("long_path") || file.Contains("CorruptedArchive.7z"))
{
continue;
}
Expand All @@ -32,6 +32,20 @@ public static List<TestFile> TestFiles
return result;
}
}

[Test]
public void CheckCorruptedFile_DisposeStream()
{
using (var extractor = new SevenZipExtractor(@"TestData\CorruptedArchive.7z"))
{
if (!extractor.Check())
{

}
}

File.OpenWrite(@"TestData\CorruptedArchive.7z");
}

[Test]
public void ExtractFilesTest()
Expand Down
Binary file added SevenZip.Tests/TestData/CorruptedArchive.7z
Binary file not shown.
5 changes: 5 additions & 0 deletions SevenZip/SevenZipExtractor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,11 @@ public bool Check()
}
catch (Exception)
{
if (_archiveStream is DisposeVariableWrapper disposeVariableWrapper)
{
disposeVariableWrapper.DisposeStream = true;
}

return false;
}
finally
Expand Down