-
Notifications
You must be signed in to change notification settings - Fork 5.4k
Description
Description
System.Formats.Tar.TarReader drops the directory prefix from entry names when reading tarballs generated by macOS bsdtar that contain symbolic links with targets exceeding 100 bytes. For example, an entry with path ./sdk/tools/net11.0/any/SomeAssembly.dll is read back as tools/net11.0/any/SomeAssembly.dll — the ./sdk/ prefix is lost.
Repro
Given a Mac-generated signed SDK tarball (e.g., dotnet-sdk-11.0.100-preview.3.26151.101-osx-x64.tar.gz):
using System.Formats.Tar;
using System.IO.Compression;
using var reader = new TarReader(new GZipStream(File.OpenRead(args[0]), CompressionMode.Decompress));
while (reader.GetNextEntry() is TarEntry entry)
{
if (!entry.Name.StartsWith("./"))
Console.WriteLine($"BROKEN: Name={entry.Name} Type={entry.EntryType} LinkName={entry.LinkName}");
}Expected: All entry names preserve their original path (e.g., ./sdk/tools/net11.0/any/...).
Actual: Certain symlink entries lose their leading directory components:
BROKEN: Name=tools/net11.0/any/Microsoft.CodeAnalysis.Workspaces.MSBuild.BuildHost.dll Type=SymbolicLink LinkName=../../../../../dotnet-format/BuildHost-netcore/Microsoft.CodeAnalysis.Workspaces.MSBuild.BuildHost.dll
BROKEN: Name=tools/net11.0/any/BuildHost-netcore/Microsoft.CodeAnalysis.Workspaces.MSBuild.BuildHost.dll Type=SymbolicLink LinkName=../../../../../../dotnet-format/BuildHost-netcore/Microsoft.CodeAnalysis.Workspaces.MSBuild.BuildHost.dll
...
Only symlinks whose link target path exceeds 100 bytes are affected. Non-symlink entries and symlinks with shorter targets read correctly.
Impact
Round-tripping a Mac tarball through TarReader/TarWriter produces a corrupted archive where affected entries are extracted to the wrong paths. This breaks scenarios like SDK installer layout generation that rely on reading and rewriting Mac tarballs. Linux-generated tarballs are not affected because GNU tar uses a different metadata format for long link targets.