Skip to content

Commit 7fd6d65

Browse files
Numpsypiksel
authored andcommitted
Merge PR #362: Don't call CleanName from the ZipEntry constructor
* unit test for reading zip files containing file names that contain invalid path characters * Don't call CleanName from the ZipEntry constructor.
1 parent ab7f8c5 commit 7fd6d65

2 files changed

Lines changed: 30 additions & 1 deletion

File tree

src/ICSharpCode.SharpZipLib/Zip/ZipEntry.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ internal ZipEntry(string name, int versionRequiredToExtract, int madeByInfo,
211211
}
212212

213213
this.DateTime = DateTime.Now;
214-
this.name = CleanName(name);
214+
this.name = name;
215215
this.versionMadeBy = (ushort)madeByInfo;
216216
this.versionToExtract = (ushort)versionRequiredToExtract;
217217
this.method = method;

test/ICSharpCode.SharpZipLib.Tests/Zip/StreamHandling.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -352,5 +352,34 @@ public void ShouldReadBZip2EntryButNotDecompress()
352352
Assert.Throws<ZipException>(() => zis.Read(buffer, 0, 1), "Trying to read the stream should throw");
353353
}
354354
}
355+
356+
/// <summary>
357+
/// Test for https://github.com/icsharpcode/SharpZipLib/issues/341
358+
/// Should be able to read entries whose names contain invalid filesystem
359+
/// characters
360+
/// </summary>
361+
[Test]
362+
[Category("Zip")]
363+
public void ShouldBeAbleToReadEntriesWithInvalidFileNames()
364+
{
365+
var testFileName = "<A|B?C>.txt";
366+
367+
using (var memoryStream = new MemoryStream())
368+
{
369+
using (var outStream = new ZipOutputStream(memoryStream))
370+
{
371+
outStream.IsStreamOwner = false;
372+
outStream.PutNextEntry(new ZipEntry(testFileName));
373+
}
374+
375+
memoryStream.Seek(0, SeekOrigin.Begin);
376+
377+
using (var inStream = new ZipInputStream(memoryStream))
378+
{
379+
var entry = inStream.GetNextEntry();
380+
Assert.That(entry.Name, Is.EqualTo(testFileName), "output name must match original name");
381+
}
382+
}
383+
}
355384
}
356385
}

0 commit comments

Comments
 (0)