Skip to content

Commit 4af855b

Browse files
authored
Handle renamed compressed .mibc files gracefully in crossgen2/dotnet-pgo (#81955)
The existing logic would throw a NullReferenceException if you renamed a compressed .mibc file and then tried to pass it to dotnet-pgo or crossgen2. This PR adds a fallback case to look for a single .dll file inside the archive when an entry with the expected name is not present. In addition throw an exception with a better error message when the lookup fails.
1 parent 4f0747d commit 4af855b

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

src/coreclr/tools/aot/ILCompiler.ReadyToRun/IBC/MIbcProfileParser.cs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,19 @@ public static PEReader OpenMibcAsPEReader(string filename)
102102
using (var zipFile = new ZipArchive(fsMibcFile, ZipArchiveMode.Read, leaveOpen: false, entryNameEncoding: null))
103103
{
104104
disposeOnException = false;
105-
var mibcDataEntry = zipFile.GetEntry(Path.GetFileName(filename) + ".dll");
105+
ZipArchiveEntry mibcDataEntry = zipFile.GetEntry(Path.GetFileName(filename) + ".dll");
106+
107+
if (mibcDataEntry == null)
108+
{
109+
// Input may have been renamed at some point; look for a single .dll inside the ZIP.
110+
mibcDataEntry = zipFile.Entries.Count == 1 ? zipFile.Entries[0] : null;
111+
112+
if (mibcDataEntry == null || !mibcDataEntry.Name.EndsWith(".dll"))
113+
{
114+
throw new InvalidDataException("Could not find input assembly in compressed MIBC file (expected archive to contain a single .dll file)");
115+
}
116+
}
117+
106118
using (var mibcDataStream = mibcDataEntry.Open())
107119
{
108120
peData = new byte[mibcDataEntry.Length];

0 commit comments

Comments
 (0)