Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't call CleanName from the ZipEntry constructor. #362

Merged
merged 2 commits into from
Jan 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
}
}
}
}
}