Skip to content

Support setting ACLs on file paths longer than MAX_PATH #92460

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

Merged
merged 2 commits into from
Sep 22, 2023
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ internal void Persist(string fullPath)
try
{
AccessControlSections persistRules = GetAccessControlSectionsFromChanges();
base.Persist(fullPath, persistRules);
base.Persist(PathInternal.EnsureExtendedPrefixIfNeeded(fullPath), persistRules);
OwnerModified = GroupModified = AuditRulesModified = AccessRulesModified = false;
}
finally
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,25 @@ public void SetAccessControl_FileInfo_FileSecurity_Success()
fileInfo.SetAccessControl(fileSecurity);
}

[Fact]
public void SetAccessControl_FileInfo_FileSecurity_Success_NameLongerThanMaxShortPath()
{
using var directory = new TempAclDirectory();

const int MaxShortPath = 260;
int fileNameLength = Math.Max(MaxShortPath - directory.Path.Length, 1);

string path = Path.Combine(directory.Path, new string('1', fileNameLength) + ".txt");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if I read right this is intended to be just ".txt" longer than 260? why not just make it 500 or something huge?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW: The path reported in the issue is 261, that's probably why just above 260 was chosen.

C:\ProgramData\UET\SDKs\Android-android-33-33.0.1-3.10.2.4988404-25.1.8937393-jdk-11.0.19+7\Sdk\cmdline-tools\lib\external\com\google\guava\listenablefuture\9999.0-empty-to-avoid-conflict-with-guava\listenablefuture-9999.0-empty-to-avoid-conflict-with-guava.jar

It doesn't hurt to test both 500 and > 260.

using var file = new TempFile(path, 1);
var fileInfo = new FileInfo(file.Path);
FileSecurity fileSecurity = fileInfo.GetAccessControl(AccessControlSections.Access);

var newAccessRule = new FileSystemAccessRule(Helpers.s_NetworkServiceNTAccount, FileSystemRights.Write, AccessControlType.Allow);
fileSecurity.SetAccessRule(newAccessRule);

fileInfo.SetAccessControl(fileSecurity);
}

[Fact]
public void SetAccessControl_FileStream_FileSecurity_InvalidArguments()
{
Expand Down