Skip to content

Commit

Permalink
fix: specialized tar extract traversal
Browse files Browse the repository at this point in the history
  • Loading branch information
piksel committed Sep 19, 2021
1 parent a0e96de commit 5c3b293
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/ICSharpCode.SharpZipLib/Tar/TarArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -658,8 +658,9 @@ private void ExtractEntry(string destDir, TarEntry entry, bool allowParentTraver
name = name.Replace('/', Path.DirectorySeparatorChar);

string destFile = Path.Combine(destDir, name);
var destFileDir = Path.GetDirectoryName(Path.GetFullPath(destFile)) ?? "";

if (!allowParentTraversal && !Path.GetFullPath(destFile).StartsWith(destDir, StringComparison.InvariantCultureIgnoreCase))
if (!allowParentTraversal && !destFileDir.StartsWith(destDir, StringComparison.InvariantCultureIgnoreCase))
{
throw new InvalidNameException("Parent traversal in paths is not allowed");
}
Expand Down

0 comments on commit 5c3b293

Please sign in to comment.