From 8885e76e992ea26ad1279624fd6429698f050f0b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Strehovsk=C3=BD?= Date: Wed, 17 Apr 2024 09:04:25 +0200 Subject: [PATCH] Improve resiliency of custom attribute parsing --- .../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 68e8b5f6f0c3..a18251e401fc 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. + } } }