1From 8fa3570bf75c48bf68f42b74790bf8ba0f032a3f Mon Sep 17 00:00:00 2001
2From: David McFarland <corngood@gmail.com>
3Date: Thu, 14 Aug 2025 10:49:40 -0300
4Subject: [PATCH] bundler: fix file size estimation when bundling symlinks
5
6---
7 .../managed/Microsoft.NET.HostModel/Bundle/Bundler.cs | 10 ++++++++--
8 1 file changed, 8 insertions(+), 2 deletions(-)
9
10diff --git a/src/runtime/src/installer/managed/Microsoft.NET.HostModel/Bundle/Bundler.cs b/src/runtime/src/installer/managed/Microsoft.NET.HostModel/Bundle/Bundler.cs
11index a5e8b593484..39f39334251 100644
12--- a/src/runtime/src/installer/managed/Microsoft.NET.HostModel/Bundle/Bundler.cs
13+++ b/src/runtime/src/installer/managed/Microsoft.NET.HostModel/Bundle/Bundler.cs
14@@ -284,6 +284,12 @@ public string GenerateBundle(IReadOnlyList<FileSpec> fileSpecs)
15 throw new ArgumentException("Invalid input specification: Must specify the host binary");
16 }
17
18+ static long GetFileLength(string path)
19+ {
20+ var info = new FileInfo(path);
21+ return ((FileInfo?)info.ResolveLinkTarget(true) ?? info).Length;
22+ }
23+
24 (FileSpec Spec, FileType Type)[] relativePathToSpec = GetFilteredFileSpecs(fileSpecs);
25 long bundledFilesSize = 0;
26 // Conservatively estimate the size of bundled files.
27@@ -293,7 +299,7 @@ public string GenerateBundle(IReadOnlyList<FileSpec> fileSpecs)
28 // We will memory map a larger file than needed, but we'll take that trade-off.
29 foreach (var (spec, type) in relativePathToSpec)
30 {
31- bundledFilesSize += new FileInfo(spec.SourcePath).Length;
32+ bundledFilesSize += GetFileLength(spec.SourcePath);
33 if (type == FileType.Assembly)
34 {
35 // Alignment could be as much as AssemblyAlignment - 1 bytes.
36@@ -314,7 +320,7 @@ public string GenerateBundle(IReadOnlyList<FileSpec> fileSpecs)
37 {
38 Directory.CreateDirectory(destinationDirectory);
39 }
40- var hostLength = new FileInfo(hostSource).Length;
41+ var hostLength = GetFileLength(hostSource);
42 var bundleManifestLength = Manifest.GetManifestLength(BundleManifest.BundleMajorVersion, relativePathToSpec.Select(x => x.Spec.BundleRelativePath));
43 long bundleTotalSize = hostLength + bundledFilesSize + bundleManifestLength;
44 if (_target.IsOSX && _macosCodesign)
45--
462.50.1
47