Skip to content

[Operational Issue]: OSX .tar.gz has broken symlinks #5281

Closed

Description

@akoeplinger

Error

Most likely related to #4879

Extracting the https://ci.dot.net/public/Sdk/11.0.100-preview.3.26128.104/dotnet-sdk-11.0.100-preview.3.26128.104-osx-x64.tar.gz results in multiple broken symlinks in the extracted output.

Interestingly the symlinks are broken differently depending on which app I use to extract !?!

Using Archive Utility or tar (symlinks look fine but don't point to correct file path):

$ find . -type l ! -exec test -e {} \; -print | xargs ls -l
lrwxr-xr-x  1 alexander  staff  128 Feb 28 15:30 ./11.0.0-preview.3.26128.104/tools/net11.0/any/Microsoft.Extensions.Configuration.Abstractions.dll -> ../../../../../dotnet-user-jwts/11.0.0-preview.3.26128.104/tools/net11.0/any/Microsoft.Extensions.Configuration.Abstractions.dll
lrwxr-xr-x  1 alexander  staff  130 Feb 28 15:30 ./11.0.0-preview.3.26128.104/tools/net11.0/any/Microsoft.Extensions.Configuration.FileExtensions.dll -> ../../../../../dotnet-user-jwts/11.0.0-preview.3.26128.104/tools/net11.0/any/Microsoft.Extensions.Configuration.FileExtensions.dll
lrwxr-xr-x  1 alexander  staff  120 Feb 28 15:30 ./11.0.0-preview.3.26128.104/tools/net11.0/any/Microsoft.Extensions.Configuration.Json.dll -> ../../../../../dotnet-user-jwts/11.0.0-preview.3.26128.104/tools/net11.0/any/Microsoft.Extensions.Configuration.Json.dll
lrwxr-xr-x  1 alexander  staff  127 Feb 28 15:30 ./11.0.0-preview.3.26128.104/tools/net11.0/any/Microsoft.Extensions.Configuration.UserSecrets.dll -> ../../../../../dotnet-user-jwts/11.0.0-preview.3.26128.104/tools/net11.0/any/Microsoft.Extensions.Configuration.UserSecrets.dll
lrwxr-xr-x  1 alexander  staff  115 Feb 28 15:30 ./11.0.0-preview.3.26128.104/tools/net11.0/any/Microsoft.Extensions.Configuration.dll -> ../../../../../dotnet-user-jwts/11.0.0-preview.3.26128.104/tools/net11.0/any/Microsoft.Extensions.Configuration.dll
lrwxr-xr-x  1 alexander  staff  128 Feb 28 15:30 ./11.0.0-preview.3.26128.104/tools/net11.0/any/Microsoft.Extensions.FileProviders.Abstractions.dll -> ../../../../../dotnet-user-jwts/11.0.0-preview.3.26128.104/tools/net11.0/any/Microsoft.Extensions.FileProviders.Abstractions.dll
lrwxr-xr-x  1 alexander  staff  124 Feb 28 15:30 ./11.0.0-preview.3.26128.104/tools/net11.0/any/Microsoft.Extensions.FileProviders.Physical.dll -> ../../../../../dotnet-user-jwts/11.0.0-preview.3.26128.104/tools/net11.0/any/Microsoft.Extensions.FileProviders.Physical.dll
lrwxr-xr-x  1 alexander  staff  104 Feb 28 15:30 ./tools/net11.0/any/BuildHost-net472/Microsoft.CodeAnalysis.Workspaces.MSBuild.BuildHost.exe -> ../../../../../../dotnet-format/BuildHost-net472/Microsoft.CodeAnalysis.Workspaces.MSBuild.BuildHost.exe
lrwxr-xr-x  1 alexander  staff  104 Feb 28 15:30 ./tools/net11.0/any/BuildHost-net472/Microsoft.CodeAnalysis.Workspaces.MSBuild.Contracts.dll -> ../../../../../../dotnet-format/BuildHost-net472/Microsoft.CodeAnalysis.Workspaces.MSBuild.Contracts.dll
lrwxr-xr-x  1 alexander  staff  105 Feb 28 15:30 ./tools/net11.0/any/BuildHost-netcore/Microsoft.CodeAnalysis.Workspaces.MSBuild.BuildHost.dll -> ../../../../../../dotnet-format/BuildHost-netcore/Microsoft.CodeAnalysis.Workspaces.MSBuild.BuildHost.dll
lrwxr-xr-x  1 alexander  staff  102 Feb 28 15:30 ./tools/net11.0/any/Microsoft.CodeAnalysis.Workspaces.MSBuild.BuildHost.dll -> ../../../../../dotnet-format/BuildHost-netcore/Microsoft.CodeAnalysis.Workspaces.MSBuild.BuildHost.dll
lrwxr-xr-x  1 alexander  staff  106 Feb 28 15:30 ./tools/net11.0/any/runtimes/win/lib/net11.0/System.Diagnostics.EventLog.Messages.dll -> ../../../../../../../../../dotnet-format/runtimes/win/lib/net11.0/System.Diagnostics.EventLog.Messages.dll

Using The Unarchiver.app (note that the file names are truncated):

$ find . -type l ! -exec test -e {} \; -print | xargs ls -l
lrwxr-xr-x@ 1 alexander  staff  100 Feb 28 15:30 ./11.0.0-preview.3.26128.104/tools/net11.0/any/Microsoft.Extensions.Configuration.Abstractions.dll -> ../../../../../dotnet-user-jwts/11.0.0-preview.3.26128.104/tools/net11.0/any/Microsoft.Extensions.Co
lrwxr-xr-x@ 1 alexander  staff  100 Feb 28 15:30 ./11.0.0-preview.3.26128.104/tools/net11.0/any/Microsoft.Extensions.Configuration.FileExtensions.dll -> ../../../../../dotnet-user-jwts/11.0.0-preview.3.26128.104/tools/net11.0/any/Microsoft.Extensions.Co
lrwxr-xr-x@ 1 alexander  staff  100 Feb 28 15:30 ./11.0.0-preview.3.26128.104/tools/net11.0/any/Microsoft.Extensions.Configuration.Json.dll -> ../../../../../dotnet-user-jwts/11.0.0-preview.3.26128.104/tools/net11.0/any/Microsoft.Extensions.Co
lrwxr-xr-x@ 1 alexander  staff  100 Feb 28 15:30 ./11.0.0-preview.3.26128.104/tools/net11.0/any/Microsoft.Extensions.Configuration.UserSecrets.dll -> ../../../../../dotnet-user-jwts/11.0.0-preview.3.26128.104/tools/net11.0/any/Microsoft.Extensions.Co
lrwxr-xr-x@ 1 alexander  staff  100 Feb 28 15:30 ./11.0.0-preview.3.26128.104/tools/net11.0/any/Microsoft.Extensions.Configuration.dll -> ../../../../../dotnet-user-jwts/11.0.0-preview.3.26128.104/tools/net11.0/any/Microsoft.Extensions.Co
lrwxr-xr-x@ 1 alexander  staff  100 Feb 28 15:30 ./11.0.0-preview.3.26128.104/tools/net11.0/any/Microsoft.Extensions.FileProviders.Abstractions.dll -> ../../../../../dotnet-user-jwts/11.0.0-preview.3.26128.104/tools/net11.0/any/Microsoft.Extensions.Fi
lrwxr-xr-x@ 1 alexander  staff  100 Feb 28 15:30 ./11.0.0-preview.3.26128.104/tools/net11.0/any/Microsoft.Extensions.FileProviders.Physical.dll -> ../../../../../dotnet-user-jwts/11.0.0-preview.3.26128.104/tools/net11.0/any/Microsoft.Extensions.Fi
lrwxr-xr-x@ 1 alexander  staff  100 Feb 28 15:30 ./tools/net11.0/any/BuildHost-net472/Microsoft.CodeAnalysis.Workspaces.MSBuild.BuildHost.exe -> ../../../../../../dotnet-format/BuildHost-net472/Microsoft.CodeAnalysis.Workspaces.MSBuild.BuildHost
lrwxr-xr-x@ 1 alexander  staff  100 Feb 28 15:30 ./tools/net11.0/any/BuildHost-net472/Microsoft.CodeAnalysis.Workspaces.MSBuild.Contracts.dll -> ../../../../../../dotnet-format/BuildHost-net472/Microsoft.CodeAnalysis.Workspaces.MSBuild.Contracts
lrwxr-xr-x@ 1 alexander  staff  100 Feb 28 15:30 ./tools/net11.0/any/BuildHost-netcore/Microsoft.CodeAnalysis.Workspaces.MSBuild.BuildHost.dll -> ../../../../../../dotnet-format/BuildHost-netcore/Microsoft.CodeAnalysis.Workspaces.MSBuild.BuildHos
lrwxr-xr-x@ 1 alexander  staff  100 Feb 28 15:30 ./tools/net11.0/any/Microsoft.CodeAnalysis.Workspaces.MSBuild.BuildHost.dll -> ../../../../../dotnet-format/BuildHost-netcore/Microsoft.CodeAnalysis.Workspaces.MSBuild.BuildHost.d
lrwxr-xr-x@ 1 alexander  staff  100 Feb 28 15:30 ./tools/net11.0/any/runtimes/win/lib/net11.0/System.Diagnostics.EventLog.Messages.dll -> ../../../../../../../../../dotnet-format/runtimes/win/lib/net11.0/System.Diagnostics.EventLog.Messag

Links

No response

Root Cause

unknown

Blocking

  • This issue is blocking

Affected Releases

  • .NET 10
  • .NET 10 (SDK band build)
  • .NET 11

Activity

  1. ericstj commented on Mar 6, 2026

    @ericstj
    Member

    Might be caused by dotnet/runtime#124753 cc @rzikm

  2. ericstj commented on Mar 6, 2026

    @ericstj
    Member

    Copilot analysis:

    Based on my analysis, PR #124753 is almost certainly NOT the cause of issue #5281. Here's my reasoning:

    What PR #124753 changed: It modified TarWriter.Windows.cs to treat non-symlink reparse points (e.g., OneDrive,
    deduplication, AppExecLinks) as regular files instead of throwing. For actual symlinks/junctions (where LinkTarget
    is non-null), behavior is unchanged. The TarWriter.Unix.cs changes were purely a method-extraction refactor — no
    behavioral change for symlinks.

    What issue #5281 describes: The OSX .tar.gz has symlinks that exist but point to invalid relative paths like
    ../../../../../dotnet-user-jwts/... — these navigate above the tar root. The symlinks are correctly written as
    symlink entries; the problem is that their relative target paths are wrong.

    The actual cause is PR #4879 (dotnet/dotnet), which introduced DeduplicateAssembliesWithLinks and
    CopyPreservingRelativeSymlinks. The deduplication creates relative symlinks between SDK tool directories (e.g., from
    one tool to dotnet-user-jwts). These relative paths reference a parent directory structure (e.g., sdk/) that gets
    stripped when the tar.gz is created, causing the ../../../../../ traversal to escape the archive root. The issue
    author also points to PR #4879 as the likely cause.

    Key evidence:

    1. The osx tar.gz is built on macOS → TarWriter.Unix.cs is used, which PR #124753 didn't meaningfully change
    2. The broken symlinks are deduplication links introduced by PR Reapply "Deduplicate files using links in mac and linux installers" (#4800) #4879, not a tar-writing bug
    3. The symlinks are properly recorded as symlink entries — the targets just reference paths outside the archive
  3. MichaelSimons commented on Mar 6, 2026

    @MichaelSimons
    Member

    First inspection indicates this is an issue w/signing. I inspected two real-signed builds and they both have this issue while 3 non-signed builds appear correct (inspected builds before and after the last re-bootstrap).

  4. ericstj commented on Mar 6, 2026

    @ericstj
    Member

    More copilot analysis -- does this pass muster @MichaelSimons

    Found the bug. It's in CopyPreservingRelativeSymlinks.CopyFile() — specifically this line:

    File.CreateSymbolicLink(destPath, sourceInfo.LinkTarget);

    It blindly preserves the original relative symlink target from the source. When the copy changes the directory
    nesting (e.g., files move from $(RedistInstallerLayoutPath)sdk/ into $(OutputPath)/sdk/ or
    $(IntermediateSdkInstallerOutputPath)sdk/$(Version)/), the relative ../ segments no longer resolve correctly.

    The fix is to recompute the relative path at the destination using the source→destination mapping that the task
    already has. Here's the corrected CopyFile symlink handling:

    // Instead of blindly reusing sourceInfo.LinkTarget:
    // File.CreateSymbolicLink(destPath, sourceInfo.LinkTarget);
    // Recompute the relative path for the destination:

    var sourceDir = Path.GetDirectoryName(Path.GetFullPath(sourcePath))!;
    var resolvedTarget = Path.GetFullPath(Path.Combine(sourceDir, sourceInfo.LinkTarget));

    if (!sourceToDestMap.TryGetValue(resolvedTarget, out var destTargetPath))
    {
    throw new InvalidOperationException(...);
    }

    var destDir = Path.GetDirectoryName(Path.GetFullPath(destPath))!;
    var newRelativePath = Path.GetRelativePath(destDir, destTargetPath);
    File.CreateSymbolicLink(destPath, newRelativePath);

    This requires building a Dictionary<string, string> mapping each source absolute path to its destination absolute
    path (from the parallel SourceFiles/DestinationFiles arrays), then passing it into CopyFile. The task already builds
    sourcePathSet for validation — the fix just extends that pattern to a full mapping so it can translate symlink
    targets into destination-relative paths.

    Your signing theory sounds reasonable too. It could be a problem repacking the tar messing up the symlinks. Not sure anyone's tested that scenario. Last year we had some round-tripping bugs there and folks tested them by pulling that roundtripping logic out of the signtool and just running it on a tar (without the signing). It made it easier to repro locally and fix - IIRC we had bugs both in the repacking tool and Tar itself.

  5. MichaelSimons commented on Mar 6, 2026

    @MichaelSimons
    Member

    More copilot analysis -- does this pass muster @MichaelSimons

    I don't think this is it. This copy logic can make some assumptions under the context of copying the SDK layout - e.g. when copying relative symbol links, the target existing within the copy scope.

    I still suspect signing - If you look at the tarball you will see there are extra top level folders - e.g. sdk sub-folders where promoted to the root of the tarball. These top level folders contain broken links because the folders are not in the correct nested location.

  6. ericstj commented on Mar 6, 2026

    @ericstj
    Member

    You can try something like this to see if it repros:

    using MemoryStream streamToCompress = new();
    using (TarWriter writer = new(streamToCompress, leaveOpen: true))
    {
    foreach (TarEntry entry in ReadTarGZipEntries(FileSignInfo.FullPath))
    {
    if (entry.DataStream != null)
    {
    string relativeName = entry.Name;
    ZipPart? signedPart = FindNestedPart(relativeName);
    if (signedPart.HasValue)
    {
    using FileStream signedStream = File.OpenRead(signedPart.Value.FileSignInfo.FullPath);
    entry.DataStream = signedStream;
    entry.DataStream.Position = 0;
    writer.WriteEntry(entry);
    log.LogMessage(MessageImportance.Low, $"Copying signed stream from {signedPart.Value.FileSignInfo.FullPath} to {FileSignInfo.FullPath} -> {relativeName} (perms: {Convert.ToString((uint)entry.Mode, 8)}).");
    continue;
    }
    log.LogMessage(MessageImportance.Low, $"Didn't find signed part for nested file: {FileSignInfo.FullPath} -> {relativeName}");
    }
    writer.WriteEntry(entry);
    }
    }

  7. MichaelSimons commented on Mar 6, 2026

    @MichaelSimons
    Member

    I was able to reproduce the issue in my linux environment by taking a non-signed osx-x64.tar.gz and unpacking/repacking it with the signtool logic in a standalone app. I then ran the tool on the linux-x64.tar.gz and it didn't reproduce. I asked copilot to analyze the difference in the osx and linux tarballs

    Exactly 12 broken entries — matching the 12 entries with pax linkpath headers!

    Root Cause Found
    The issue is a bug in .NET's System.Formats.Tar when writing symbolic link entries that have pax extended linkpath headers (used when the link target exceeds the 100-byte ustar limit).

    Here's what happens:

    Mac tarball has 12 symlinks with link targets >100 bytes, requiring pax linkpath extended headers
    Linux tarball also has 12 symlinks with link targets >100 bytes, but they do NOT have pax linkpath headers (they must be using a different encoding, like GNU long link extensions)
    When System.Formats.Tar reads and re-writes the Mac entries with pax linkpath headers, it corrupts the entry names, stripping the path prefix and turning them into broken top-level entries
    This is not a Mac platform issue or a symlink handling issue. It's a System.Formats.Tar bug when round-tripping pax extended linkpath headers on symbolic link entries.

    The two tarballs use different tar implementations that encode long link targets differently:

    Linux tar (GNU tar): Uses GNU long link extension → System.Formats.Tar handles correctly
    Mac tar (BSD tar): Uses pax linkpath extended headers → System.Formats.Tar corrupts these on round-trip

  8. MichaelSimons commented on Mar 6, 2026

    @MichaelSimons
    Member

    @ericstj - does this analysis pass muster to you?

  9. MichaelSimons commented on Mar 9, 2026

    @MichaelSimons
    Member

    I logged dotnet/runtime#125332 with a simple repro from a Mac generated tarball with long symbolic link paths.

  10. ericstj commented on Mar 9, 2026

    @ericstj
    Member

    Yeah, makes sense. @rzikm we'll need to get this fixed ASAP. @MichaelSimons I don't suppose you have a read on whether this is a regression or not, since this is the first time this is being used in the product?

  11. MichaelSimons commented on Mar 9, 2026

    @MichaelSimons
    Member

    Yeah, makes sense. @rzikm we'll need to get this fixed ASAP. @MichaelSimons I don't suppose you have a read on whether this is a regression or not, since this is the first time this is being used in the product?

    It is not a recent regression. This will reproduce on both 9 and 10. I didn't try any other older versions.

  12. ericstj commented on Mar 9, 2026

    @ericstj
    Member

    Looks like there might be a workaround - set the path in extended attributes. @MichaelSimons not sure if a workaround might help things here. Looks like @rzikm was fast with the fix in 11.

  13. yinjiehe01 commented on Mar 10, 2026

    @yinjiehe01

    This issue does not repro on SDK 11.0.100-preview.2.26159.112 and still repro on SDK 11.0.100-preview.3.26157.103

  14. MichaelSimons commented on Mar 17, 2026

    @MichaelSimons
    Member

    Verified this is fixed on the tip of main - 11.0.100-preview.3.26164.102

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions