You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Merge PR# 311: Set isStreamOwner from ZipFile constructor in FastZip.ExtractZip
* Change FastZip.ExtractZip to use the new ZipFile constructor to set isStreamOwner, rather than setting the property after construction.
* Add unit tests for testing that FastZip.Extract handles stream disposal a bit better when handling a corrupt zip file
Assert.That(Directory.Exists(tempFolderPath),Is.False,"Temp folder path should not exist");
463
+
464
+
// memory that isn't a valid zip
465
+
varms=newTrackedMemoryStream(newbyte[32]);
466
+
Assert.IsFalse(ms.IsClosed,"Underlying stream should NOT be closed initially");
467
+
468
+
// Try to extract
469
+
varfastZip=newFastZip();
470
+
fastZip.CreateEmptyDirectories=true;
471
+
472
+
Assert.Throws<ZipException>(()=>fastZip.ExtractZip(ms,tempFolderPath,FastZip.Overwrite.Always,null,"a","b",false,false),"Should throw when extracting an invalid file");
473
+
Assert.IsFalse(ms.IsClosed,"inputStream stream should NOT be closed when isStreamOwner is false");
474
+
475
+
// test folder should not have been created on error
476
+
Assert.That(Directory.Exists(tempFolderPath),Is.False,"Temp folder path should still not exist");
477
+
}
478
+
479
+
/// <summary>
480
+
/// Check that the input stream is closed on error when isStreamOwner is true
481
+
/// </summary>
482
+
[Test]
483
+
publicvoidStreamClosedOnError()
484
+
{
485
+
// test paths
486
+
stringtempFilePath=GetTempFilePath();
487
+
Assert.IsNotNull(tempFilePath,"No permission to execute this test?");
Assert.That(Directory.Exists(tempFolderPath),Is.False,"Temp folder path should not exist");
491
+
492
+
// memory that isn't a valid zip
493
+
varms=newTrackedMemoryStream(newbyte[32]);
494
+
Assert.IsFalse(ms.IsClosed,"Underlying stream should NOT be closed initially");
495
+
496
+
// Try to extract
497
+
varfastZip=newFastZip();
498
+
fastZip.CreateEmptyDirectories=true;
499
+
500
+
Assert.Throws<ZipException>(()=>fastZip.ExtractZip(ms,tempFolderPath,FastZip.Overwrite.Always,null,"a","b",false,true),"Should throw when extracting an invalid file");
501
+
Assert.IsTrue(ms.IsClosed,"inputStream stream should be closed when isStreamOwner is true");
502
+
503
+
// test folder should not have been created on error
504
+
Assert.That(Directory.Exists(tempFolderPath),Is.False,"Temp folder path should still not exist");
0 commit comments