Skip to content

Commit

Permalink
fix: add dir separator to base dir if missing
Browse files Browse the repository at this point in the history
  • Loading branch information
piksel committed May 8, 2021
1 parent 2e3e2e8 commit 4875a45
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/ICSharpCode.SharpZipLib/Zip/WindowsNameTransform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,12 @@ public string TransformFile(string name)
{
name = Path.Combine(_baseDirectory, name);

var pathBase = Path.GetFullPath(_baseDirectory) + Path.DirectorySeparatorChar;
// Ensure base directory ends with directory separator ('/' or '\' depending on OS)
var pathBase = Path.GetFullPath(_baseDirectory);
if (pathBase[pathBase.Length - 1] != Path.DirectorySeparatorChar)
{
pathBase += Path.DirectorySeparatorChar;
}

if (!_allowParentTraversal && !Path.GetFullPath(name).StartsWith(pathBase, StringComparison.InvariantCultureIgnoreCase))
{
Expand Down

0 comments on commit 4875a45

Please sign in to comment.