diff --git a/src/coreclr/tools/Common/Compiler/CompilerTypeSystemContext.cs b/src/coreclr/tools/Common/Compiler/CompilerTypeSystemContext.cs index db8ad465dc2fe3..f7f7baf2c8158d 100644 --- a/src/coreclr/tools/Common/Compiler/CompilerTypeSystemContext.cs +++ b/src/coreclr/tools/Common/Compiler/CompilerTypeSystemContext.cs @@ -328,7 +328,15 @@ private PdbSymbolReader OpenAssociatedSymbolFile(string peFilePath, PEReader peR if (debugEntry.Type != DebugDirectoryEntryType.CodeView) continue; - CodeViewDebugDirectoryData debugDirectoryData = peReader.ReadCodeViewDebugDirectoryData(debugEntry); + CodeViewDebugDirectoryData debugDirectoryData; + try + { + debugDirectoryData = peReader.ReadCodeViewDebugDirectoryData(debugEntry); + } + catch (BadImageFormatException) + { + continue; + } string candidatePath = debugDirectoryData.Path; if (!Path.IsPathRooted(candidatePath) || !File.Exists(candidatePath)) diff --git a/src/coreclr/tools/dotnet-pgo/TraceTypeSystemContext.cs b/src/coreclr/tools/dotnet-pgo/TraceTypeSystemContext.cs index 33e11d92d023b1..3d90930c8aad3f 100644 --- a/src/coreclr/tools/dotnet-pgo/TraceTypeSystemContext.cs +++ b/src/coreclr/tools/dotnet-pgo/TraceTypeSystemContext.cs @@ -369,7 +369,15 @@ private PdbSymbolReader OpenAssociatedSymbolFile(string peFilePath, PEReader peR if (debugEntry.Type != DebugDirectoryEntryType.CodeView) continue; - CodeViewDebugDirectoryData debugDirectoryData = peReader.ReadCodeViewDebugDirectoryData(debugEntry); + CodeViewDebugDirectoryData debugDirectoryData; + try + { + debugDirectoryData = peReader.ReadCodeViewDebugDirectoryData(debugEntry); + } + catch (BadImageFormatException) + { + continue; + } string candidatePath = debugDirectoryData.Path; if (!Path.IsPathRooted(candidatePath) || !File.Exists(candidatePath))