@@ -1692,7 +1692,7 @@ public void TestDescriptorUpdateOnAdd([Values] UseZip64 useZip64, [Values] FileU
1692
1692
/// <param name="updateMode">Whether safe or direct updates should be used</param>
1693
1693
[ Test ]
1694
1694
[ Category ( "Zip" ) ]
1695
- public void TestDescriptorUpdateOnReplacee ( [ Values ] UseZip64 useZip64 , [ Values ] FileUpdateMode updateMode )
1695
+ public void TestDescriptorUpdateOnReplace ( [ Values ] UseZip64 useZip64 , [ Values ] FileUpdateMode updateMode )
1696
1696
{
1697
1697
MemoryStream msw = new MemoryStreamWithoutSeek ( ) ;
1698
1698
using ( ZipOutputStream outStream = new ZipOutputStream ( msw ) )
@@ -1742,5 +1742,63 @@ public void TestDescriptorUpdateOnReplacee([Values] UseZip64 useZip64, [Values]
1742
1742
}
1743
1743
}
1744
1744
}
1745
+
1746
+ // This is the initial zipfile generated by the 'TestDescriptorUpdateOnReplace' test, but with descriptor
1747
+ // fields that don't have the signature bytes.
1748
+ const string TestZipFileWithSignaturelessDescriptors = @"UEsDBBQACAAIAHO8E1EAAAAAAAAAAAAAAAANAAAA
1749
+ U3RyaXBlZE1hcmxpbosEAN0GtcADAAAAAQAAAFBLAwQUAAgACABzvBNRAAAAAAAAAAAAAAAACwAAAFdoaXRlTWFybGlui
1750
+ wYA8We7LgMAAAABAAAAUEsDBBQACAAIAHO8E1EAAAAAAAAAAAAAAAAIAAAAU2FpbGZpc2hjBgA3vgtLAwAAAAEAAABQSw
1751
+ ECMwAUAAgACABzvBNR3Qa1wAMAAAABAAAADQAAAAAAAAAAAAAAAAAAAAAAU3RyaXBlZE1hcmxpblBLAQIzABQACAAIAHO
1752
+ 8E1HxZ7suAwAAAAEAAAALAAAAAAAAAAAAAAAAADoAAABXaGl0ZU1hcmxpblBLAQIzABQACAAIAHO8E1E3vgtLAwAAAAEA
1753
+ AAAIAAAAAAAAAAAAAAAAAHIAAABTYWlsZmlzaFBLBQYAAAAAAwADAKoAAACnAAAAAAA=" ;
1754
+
1755
+ /// <summary>
1756
+ /// Test for https://github.com/icsharpcode/SharpZipLib/issues/147, when replacing items in a zip, using a file whose descriptors
1757
+ /// don't have signature bytes
1758
+ /// </summary>
1759
+ /// <param name="useZip64">Whether Zip64 should be used in the test archive</param>
1760
+ /// <param name="updateMode">Whether safe or direct updates should be used</param>
1761
+ [ Test ]
1762
+ [ Category ( "Zip" ) ]
1763
+ public void TestSignaturelessDescriptorUpdateOnReplace ( [ Values ] UseZip64 useZip64 , [ Values ] FileUpdateMode updateMode )
1764
+ {
1765
+ var fileBytes = Convert . FromBase64String ( TestZipFileWithSignaturelessDescriptors ) ;
1766
+
1767
+ using ( var memoryStream = new MemoryStream ( ) )
1768
+ {
1769
+ memoryStream . Write ( fileBytes , 0 , fileBytes . Length ) ;
1770
+ memoryStream . Position = 0 ;
1771
+
1772
+ using ( var zipFile = new ZipFile ( memoryStream , leaveOpen : true ) )
1773
+ {
1774
+ zipFile . BeginUpdate ( new MemoryArchiveStorage ( updateMode ) ) ;
1775
+ zipFile . Delete ( "WhiteMarlin" ) ;
1776
+ zipFile . Add ( new StringMemoryDataSource ( "Kajikia albida" ) , "WhiteMarlin" ) ;
1777
+ zipFile . CommitUpdate ( ) ;
1778
+
1779
+ // @@NOTE@@ TestArchive fails if an entry has a descriptor with no signature.
1780
+ // Assert.That(zipFile.TestArchive(true), Is.True);
1781
+ Assert . That ( zipFile . Count , Is . EqualTo ( 3 ) ) ;
1782
+
1783
+ // Test for expected descriptor states:
1784
+ // 'StripedMarlin' should still have a descriptor in Direct update mode as the entry data will be kept, but won't have one
1785
+ // in Safe update mode as that recreates the whole archive.
1786
+ // 'WhiteMarlin' should no longer have one because the entry is new and didn't need one
1787
+ // 'Sailfish' should have its descriptor removed.
1788
+ var entry = zipFile . GetEntry ( "StripedMarlin" ) ;
1789
+
1790
+ if ( updateMode == FileUpdateMode . Direct )
1791
+ Assert . True ( ( ( GeneralBitFlags ) entry . Flags ) . HasFlag ( GeneralBitFlags . Descriptor ) ) ;
1792
+ else
1793
+ Assert . False ( ( ( GeneralBitFlags ) entry . Flags ) . HasFlag ( GeneralBitFlags . Descriptor ) ) ;
1794
+
1795
+ entry = zipFile . GetEntry ( "WhiteMarlin" ) ;
1796
+ Assert . False ( ( ( GeneralBitFlags ) entry . Flags ) . HasFlag ( GeneralBitFlags . Descriptor ) ) ;
1797
+
1798
+ entry = zipFile . GetEntry ( "Sailfish" ) ;
1799
+ Assert . False ( ( ( GeneralBitFlags ) entry . Flags ) . HasFlag ( GeneralBitFlags . Descriptor ) ) ;
1800
+ }
1801
+ }
1802
+ }
1745
1803
}
1746
1804
}
0 commit comments