-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
FileSystemAclExtensions.Create broken in multiple ways #57768
Comments
Tagging subscribers to this area: @dotnet/area-system-io Issue DetailsOn .NET Framework, this: using System;
using System.IO;
using System.Security.AccessControl;
internal class Program
{
static void Main()
{
string path = @"tmp.txt";
using (FileStream fs = new FileStream(path, FileMode.Create, FileSystemRights.AppendData, FileShare.None, 1, FileOptions.None, null))
{
for (int i = 0; i < 26; i++)
{
fs.WriteByte((byte)('a' + i));
fs.Position = 0;
}
}
const string Expected = "abcdefghijklmnopqrstuvwxyz";
string text = File.ReadAllText(path);
Console.WriteLine(text == Expected ?
"Success" :
$"Expected {Expected}, got {text}");
}
} produces:
On .NET 5/6, you should be able to use FileStreamAclExtensions.Create in the exact same way (its whole purpose for existing is to provide the exact same functionality on core): using System;
using System.IO;
using System.Security.AccessControl;
internal class Program
{
static void Main()
{
string path = @"tmp.txt";
using (FileStream fs = FileSystemAclExtensions.Create(new FileInfo(path), FileMode.Create, FileSystemRights.AppendData, FileShare.None, 1, FileOptions.None, null))
{
for (int i = 0; i < 26; i++)
{
fs.WriteByte((byte)('a' + i));
fs.Position = 0;
}
}
const string Expected = "abcdefghijklmnopqrstuvwxyz";
string text = File.ReadAllText(path);
Console.WriteLine(text == Expected ?
"Success" :
$"Expected {Expected}, got {text}");
}
} but that blows up with an ArgumentNullException:
If you then fix that to allow null, it then fails deeper with how it's mapping to FileStream validation of FileAccess:
|
I don't think this meets the bar for 6.0, we should probably address it in 7.0 though. |
The fix would most probably be easy, the question is whether we would be able to include it in 6.0 |
As a regression from .NET Framework, this would be a reasonable fix to take in RC2 so long as we're very confident in the changes and we evaluate/mitigate the potential risks. Ideally we'd get validation from |
Is the behavior not expected to be the same if the last argument is |
This was introduced in 5.0, and also the |
No, the implementation on .NET Framework has multiple checks that differentiate behavior when it's null and not null, e.g.
The API reviewers aren't experts in all the functionality for each area and trust the proposer for things like this. If it should be nullable, we can make it nullable. |
I have a partial fix for this - The API now accepts a For the second exception, I am still trying to decide how to best address this. In .NET Framework, if the And because all this ACL logic was done directly in the In our .NET 7.0, we generate the ACL logic in the extension method, then pass the handle and arguments to the runtime/src/libraries/System.Private.CoreLib/src/System/IO/Strategies/FileStreamHelpers.cs Lines 86 to 89 in 6115ca2
And because not all of their values match, we can't just cast the
So I'm inclined to fix this by analyzing all the values of runtime/src/libraries/System.IO.FileSystem.AccessControl/src/System/IO/FileSystemAclExtensions.cs Lines 259 to 275 in 57bfe47
|
@carlossanlop I have code that was just migrated from .NET 4.8 to .NET 6 and ran into |
I found another bug in the extension method: If This does not happen in .NET Framework. I found the root cause: The I'll include this fix in the PR. |
On .NET Framework, this:
produces:
On .NET 5/6, you should be able to use FileStreamAclExtensions.Create in the exact same way (its whole purpose for existing is to provide the exact same functionality on core):
but that blows up with an ArgumentNullException:
If you then fix that to allow null, it then fails deeper with how it's mapping to FileStream validation of FileAccess:
The text was updated successfully, but these errors were encountered: