Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix infinite recursion writing to removable drives mounted to NTFS folders #3415

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
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
16 changes: 12 additions & 4 deletions pxr/base/tf/fileUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,22 @@ Tf_HasAttribute(

// Ignore reparse points on network volumes. They can't be resolved
// properly, so simply remove the reparse point attribute and treat
// it like a regular file/directory.
// it like a regular file/directory. Also ignore reparse points where
// TfReadLink returns the passed in path. As described in ArchReadLink,
// this will happen in cases where the reparse points are NT Object
// Manager paths, which cannot be used as file paths. Or if TfReadLink
// returns an empty string, that means we could not resolve the link
// at all, so treat it as if it is not a link.
std::string linkPath;
if ((attribs & FILE_ATTRIBUTE_REPARSE_POINT) != 0) {
// Calling PathIsNetworkPath sometimes sets the "last error" to an
// error code indicating an incomplete overlapped I/O function. We
// want to ignore this error.
DWORD olderr = GetLastError();
if (PathIsNetworkPathW(pathW.c_str())) {
linkPath = TfReadLink(path.c_str());
if (PathIsNetworkPathW(pathW.c_str()) ||
linkPath.empty() ||
path == linkPath) {
attribs &= ~FILE_ATTRIBUTE_REPARSE_POINT;
}
SetLastError(olderr);
Expand All @@ -106,8 +115,7 @@ Tf_HasAttribute(
}

// Read symlinks until we find the real file.
return Tf_HasAttribute(TfReadLink(path.c_str()), resolveSymlinks,
attribute, expected);
return Tf_HasAttribute(linkPath, resolveSymlinks, attribute, expected);
}

// Same as above but the bits in attribute must all be set.
Expand Down
8 changes: 2 additions & 6 deletions pxr/base/tf/pathUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,8 @@ _ExpandSymlinks(const std::string& path)
prefix.push_back('\\');
}
if (TfIsLink(prefix)) {
// Expand the link and repeat with the new path if the path changed.
// The path may remain unchanged or be empty if the link type is
// unsupported or the mount destination is not available.
auto newPrefix = TfReadLink(prefix);
if (!newPrefix.empty() && newPrefix != prefix)
return _ExpandSymlinks(newPrefix + path.substr(i));
// Expand the link and repeat with the new path.
return _ExpandSymlinks(TfReadLink(prefix) + path.substr(i));
}
i = path.find_first_of("/\\", i + 1);
}
Expand Down