From 006be09a29e2299f3db2941e6632a7e8d40825d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Thu, 18 Apr 2024 02:00:21 +0900 Subject: [PATCH] Improve resiliency of custom attribute parsing (#101164) --- .../CustomAttributeBasedDependencyAlgorithm.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/CustomAttributeBasedDependencyAlgorithm.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/CustomAttributeBasedDependencyAlgorithm.cs index 68e8b5f6f0c39..a18251e401fc0 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/CustomAttributeBasedDependencyAlgorithm.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/DependencyAnalysis/CustomAttributeBasedDependencyAlgorithm.cs @@ -1,6 +1,7 @@ // Licensed to the .NET Foundation under one or more agreements. // The .NET Foundation licenses this file to you under the MIT license. +using System; using System.Collections.Immutable; using System.Diagnostics; using System.Reflection.Metadata; @@ -151,6 +152,12 @@ private static void AddDependenciesDueToCustomAttributes(ref DependencyList depe // worth the hassle: the input was invalid. The most important thing is that we // don't crash the compilation. } + catch (BadImageFormatException) + { + // System.Reflection.Metadata will throw BadImageFormatException if the blob is malformed. + // This can happen if e.g. underlying type of an enum changes between versions and + // we can no longer decode the custom attribute blob. + } } }