From 4875a4502288e7a0e4b73a93ba0eda5998a696f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?nils=20m=C3=A5s=C3=A9n?= Date: Sat, 8 May 2021 15:35:24 +0200 Subject: [PATCH] fix: add dir separator to base dir if missing --- src/ICSharpCode.SharpZipLib/Zip/WindowsNameTransform.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/ICSharpCode.SharpZipLib/Zip/WindowsNameTransform.cs b/src/ICSharpCode.SharpZipLib/Zip/WindowsNameTransform.cs index 4958df41b..43aa61403 100644 --- a/src/ICSharpCode.SharpZipLib/Zip/WindowsNameTransform.cs +++ b/src/ICSharpCode.SharpZipLib/Zip/WindowsNameTransform.cs @@ -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)) {