-
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
How to properly set umask in TarEntry and ZipFileExtensions #69760
Comments
Tagging subscribers to this area: @dotnet/area-system-io-compression Issue DetailsThis question is related to one of the items in the tar pending feedback issue: #68230 In the initial Tar implementation PR, @tmds pointed out here and here that the code setting the mode when extracting files in Unix was incorrect because the The proposed solution would be to call the I examined that I also noticed that the code in ZipFileExtensions.ZipArchiveEntry.Extract.Unix.cs has the same problem of ignoring the umask (cc @eerhardt). So I have the following questions:
Interop.CheckIo(
Interop.Sys.FChMod(fs.SafeFileHandle, permissions & (int)Interop.Sys.Permissions.Mask),
fs.Name);
|
The umask protects the user from unintentional opening up files/directories to other users. The
#67837 will provide a way to do this.
The kernel tracks the process It doesn't get used for calls like
imo, we should have the same behavior as
The rationale is provided in a comment: Lines 20 to 26 in 0dba0ee
|
I should have used "fixes" in the message. We can close this when that PR is merged. |
This question is related to one of the items in the tar pending feedback issue: #68230
In the initial Tar implementation PR, @tmds pointed out here and here that the code setting the mode when extracting files in Unix was incorrect because the
umask
is being ignored.The proposed solution would be to call the
SafeFileHandle.Open()
static method that takes anInterop.Sys.Permissions
argument. The problem is that this method is internal. The only places where we call it are inFile
,FileStream
andFileSystem.Unix.cs
, which all reside inSystem.Private.CoreLib
.I examined that
Open
method, and when it callsSafeFileHandle.Init
here, that is when we interact with theumask
, which we consume here.I also noticed that the code in ZipFileExtensions.ZipArchiveEntry.Extract.Unix.cs has the same problem of ignoring the umask (cc @eerhardt).
So I have the following questions:
Why do we use the hardcoded Interop.Sys.Permissions.Mask in
SafeFileHandle
, instead of the one desired by the user, which according to various documentation sources (like this one) is usually set in the.profile
file or in/etc/profile
?If we all think it is the right thing to use that hardcoded mask, can I simply just do the following for both
TarEntry
andZipFileExtensions
?:if (permisions != 0)
. This code is identical to the one inZipFileExtensions
. Do we need that protection at all? @eerhardt would there be unexpected behavior if we remove thatif
?The text was updated successfully, but these errors were encountered: