Skip to content
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -544,8 +544,13 @@ public void ExtractToDirectory_RejectsChainedSymlinkDirectoryTraversal_WithNeste

if (OperatingSystem.IsWindows())
{
// Windows only creates file symlinks and trying to process a directory symlink will throw UnauthorizedAccessException instead of IOException
Assert.Throws<UnauthorizedAccessException>(() => TarFile.ExtractToDirectory(tarPath, destDir, overwriteFiles: true));
// Windows only creates file symlinks. Processing the chained directory symlink usually
// surfaces as UnauthorizedAccessException, but depending on the order in which the entries
// are extracted the colliding directory creation can instead surface as IOException
// ("a file or directory with the same name already exists"). Either way the traversal is
// rejected before anything escapes the destination, which the assertions below verify.
Exception ex = Assert.ThrowsAny<Exception>(() => TarFile.ExtractToDirectory(tarPath, destDir, overwriteFiles: true));
Assert.True(ex is UnauthorizedAccessException or IOException, $"Unexpected exception type: {ex.GetType()}");
}
else
{
Expand Down