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 TarWriter.TarEntry exception when adding file whose Unix group owner does not exist in the system #81070

Merged
merged 7 commits into from
Jan 25, 2023

Conversation

carlossanlop
Copy link
Member

Fixes #81047
Addresses dotnet/sdk-container-builds#246

Users in MacOSX ARM are seeing an exception show up when executing dotnet publish. The exception shows up when the test container is created and the TarWriterWriteEntry(fileName, entryName) is called. The method is throwing when attempting to add a file whose Unix group doesn't exist in the current machine.

The root cause is that when we call the native method that retrieves a groupName using a groupId, the P/Invoke that wraps it throws an exception if the returned string is null.

WriteEntry should be able to continue writing the rest of the entry with an empty groupName if such group is not found in the current system using the groupId. In this case, the groupName field should simply be an empty string.

Added a couple of tests that create a randomly named group, create a file in disk, assigns the group as owner of the file, then deletes the group, then adds the file as an entry to the archive.

I deleted a method that was not used anywhere but in a test file. For future reference, if we need to bring it back, it should also add a new resource string with a more useful error message for when the errno is 0 and the string is null:

This affects users from .NET 7, so we will need to backport it.

        /// <summary>
        /// Gets the group name associated to the specified group ID.
        /// </summary>
        /// <param name="gid">The group ID.</param>
        /// <returns>On success, return a string with the group name. On failure, throws an IOException.</returns>
        internal static string GetGroupName(uint gid)
        {
            string? groupName = GetGroupNameInternal(gid);
            ErrorInfo error = GetLastErrorInfo();
            if (groupName == null && error.RawErrno == 0)
            {
                throw new IOException(SR.Format(SR.IO_GroupNotFound, gid));
            }
            else
            {
                throw GetIOException(error);
            }
        }

cc @baronfel @rainersigwald

Copy link
Member

@adamsitnik adamsitnik left a comment

Choose a reason for hiding this comment

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

LGTM, thank you for providing the fix @carlossanlop. If you like my suggestions please apply them before merging.

Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

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

LGTM. Thanks for fixing this, @carlossanlop!

@carlossanlop
Copy link
Member Author

CI failures are all unrelated:

  • Libraries Test Run release coreclr windows x86 Release and Libraries Test Run release coreclr windows x64 Debug

  • Libraries Test Run release mono linux arm64 Debug

    • At least 3 Generator Roslyn tests failing with this known issue: Roslyn source generator crash on mono/linux/arm64 #81123
      • Microsoft.Extensions.Logging.Generators.Roslyn3.11.Tests
      • System.Text.Json.SourceGeneration.Roslyn4.4.Tests
      • Microsoft.Extensions.Logging.Generators.Roslyn4.0.Tests

@carlossanlop
Copy link
Member Author

/backport to release/7.0

@github-actions
Copy link
Contributor

Started backporting to release/7.0: https://github.com/dotnet/runtime/actions/runs/4001696599

@carlossanlop carlossanlop merged commit 1bcd55a into dotnet:main Jan 25, 2023
@carlossanlop carlossanlop deleted the TarGNameFix branch January 25, 2023 01:18
p.StartInfo.RedirectStandardError = true;

p.Start();
p.WaitForExit();
Copy link
Member

Choose a reason for hiding this comment

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

this is using the pattern that is prone to a famous deadlock
https://learn.microsoft.com/en-us/dotnet/api/system.diagnostics.process.standardoutput?view=net-7.0#remarks

it will only occur if there is a sufficiently large amount of output, so this could well be fine here, but just FYI that this is not a good pattern to use in general.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed. Better late than never: #83126

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Erroneous IOException in TarWriter.WriteEntry on MacOS
6 participants