Skip to content

Commit 79e80a8

Browse files
authored
Refactor reparse tag checks (PowerShell#10431)
Reparse tag consts is absolute numbers, not flags so we should use a comparison instead of bit operations
1 parent ee8e4e0 commit 79e80a8

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/System.Management.Automation/namespaces/FileSystemProvider.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,7 +1845,7 @@ private void Dir(
18451845
// a) the user has asked to with the -FollowSymLinks switch parameter and
18461846
// b) the directory pointed to by the symlink has not already been visited,
18471847
// preventing symlink loops.
1848-
// c) it is not a reparse point with a target
1848+
// c) it is not a reparse point with a target (not OneDrive or an AppX link).
18491849
if (tracker == null)
18501850
{
18511851
if (InternalSymbolicLinkLinkCodeMethods.IsReparsePointWithTarget(recursiveDirectory))
@@ -8069,13 +8069,15 @@ internal static bool IsReparsePointWithTarget(FileSystemInfo fileInfo)
80698069
return false;
80708070
}
80718071
#if !UNIX
8072+
// It is a reparse point and we should check some reparse point tags.
80728073
var data = new WIN32_FIND_DATA();
80738074
using (var handle = FindFirstFileEx(fileInfo.FullName, FINDEX_INFO_LEVELS.FindExInfoBasic, ref data, FINDEX_SEARCH_OPS.FindExSearchNameMatch, IntPtr.Zero, 0))
80748075
{
8075-
// Name surrogates (0x20000000) are reparse points that point to other named entities local to the filesystem (like symlinks)
8076-
// In the case of OneDrive, they are not surrogates and would be safe to recurse into.
8077-
// This code is equivalent to the IsReparseTagNameSurrogate macro: https://docs.microsoft.com/en-us/windows-hardware/drivers/ddi/content/ntifs/nf-ntifs-isreparsetagnamesurrogate
8078-
if (!handle.IsInvalid && (data.dwReserved0 & 0x20000000) == 0 && (data.dwReserved0 & IO_REPARSE_TAG_APPEXECLINK) != IO_REPARSE_TAG_APPEXECLINK)
8076+
// The name surrogate bit 0x20000000 is defined in https://docs.microsoft.com/en-us/windows/win32/fileio/reparse-point-tags
8077+
// Name surrogates (0x20000000) are reparse points that point to other named entities local to the filesystem
8078+
// (like symlinks and mount points).
8079+
// In the case of OneDrive, they are not name surrogates and would be safe to recurse into.
8080+
if (!handle.IsInvalid && (data.dwReserved0 & 0x20000000) == 0 && (data.dwReserved0 != IO_REPARSE_TAG_APPEXECLINK))
80798081
{
80808082
return false;
80818083
}

0 commit comments

Comments
 (0)