From 20e0c497ac3d211fa2d962f9ef0a23ea391a333a Mon Sep 17 00:00:00 2001 From: Richard Webb Date: Sat, 22 Jun 2019 22:57:41 +0100 Subject: [PATCH 1/2] unit test for reading zip files containing file names that contain invalid path characters --- .../Zip/StreamHandling.cs | 29 +++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/test/ICSharpCode.SharpZipLib.Tests/Zip/StreamHandling.cs b/test/ICSharpCode.SharpZipLib.Tests/Zip/StreamHandling.cs index a2a9f635b..32920503e 100644 --- a/test/ICSharpCode.SharpZipLib.Tests/Zip/StreamHandling.cs +++ b/test/ICSharpCode.SharpZipLib.Tests/Zip/StreamHandling.cs @@ -352,5 +352,34 @@ public void ShouldReadBZip2EntryButNotDecompress() Assert.Throws(() => zis.Read(buffer, 0, 1), "Trying to read the stream should throw"); } } + + /// + /// Test for https://github.com/icsharpcode/SharpZipLib/issues/341 + /// Should be able to read entries whose names contain invalid filesystem + /// characters + /// + [Test] + [Category("Zip")] + public void ShouldBeAbleToReadEntriesWithInvalidFileNames() + { + var testFileName = ".txt"; + + using (var memoryStream = new MemoryStream()) + { + using (var outStream = new ZipOutputStream(memoryStream)) + { + outStream.IsStreamOwner = false; + outStream.PutNextEntry(new ZipEntry(testFileName)); + } + + memoryStream.Seek(0, SeekOrigin.Begin); + + using (var inStream = new ZipInputStream(memoryStream)) + { + var entry = inStream.GetNextEntry(); + Assert.That(entry.Name, Is.EqualTo(testFileName), "output name must match original name"); + } + } + } } } From 44a98e17cdfbead5ff6e9c01c1ecd4c772c41c7d Mon Sep 17 00:00:00 2001 From: Richard Webb Date: Sat, 22 Jun 2019 23:11:27 +0100 Subject: [PATCH 2/2] Don't call CleanName from the ZipEntry constructor. --- src/ICSharpCode.SharpZipLib/Zip/ZipEntry.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ICSharpCode.SharpZipLib/Zip/ZipEntry.cs b/src/ICSharpCode.SharpZipLib/Zip/ZipEntry.cs index 730d8e48c..d5105b5ab 100644 --- a/src/ICSharpCode.SharpZipLib/Zip/ZipEntry.cs +++ b/src/ICSharpCode.SharpZipLib/Zip/ZipEntry.cs @@ -211,7 +211,7 @@ internal ZipEntry(string name, int versionRequiredToExtract, int madeByInfo, } this.DateTime = DateTime.Now; - this.name = CleanName(name); + this.name = name; this.versionMadeBy = (ushort)madeByInfo; this.versionToExtract = (ushort)versionRequiredToExtract; this.method = method;