Skip to content

Commit

Permalink
Merge PR #362: Don't call CleanName from the ZipEntry constructor
Browse files Browse the repository at this point in the history
* unit test for reading zip files containing file names that contain invalid path characters
* Don't call CleanName from the ZipEntry constructor.
  • Loading branch information
Numpsy authored and piksel committed Jan 27, 2020
1 parent ab7f8c5 commit 7fd6d65
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/ICSharpCode.SharpZipLib/Zip/ZipEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
29 changes: 29 additions & 0 deletions test/ICSharpCode.SharpZipLib.Tests/Zip/StreamHandling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -352,5 +352,34 @@ public void ShouldReadBZip2EntryButNotDecompress()
Assert.Throws<ZipException>(() => zis.Read(buffer, 0, 1), "Trying to read the stream should throw");
}
}

/// <summary>
/// Test for https://github.com/icsharpcode/SharpZipLib/issues/341
/// Should be able to read entries whose names contain invalid filesystem
/// characters
/// </summary>
[Test]
[Category("Zip")]
public void ShouldBeAbleToReadEntriesWithInvalidFileNames()
{
var testFileName = "<A|B?C>.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");
}
}
}
}
}

0 comments on commit 7fd6d65

Please sign in to comment.