From 7fe78813fbd67a581aedb0d65500b6db12a3ca54 Mon Sep 17 00:00:00 2001 From: Mason Wheeler Date: Thu, 30 Dec 2021 06:47:12 -0700 Subject: [PATCH 1/3] Fixing a crash bug --- src/coreclr/tools/Common/TypeSystem/Ecma/EcmaModule.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaModule.cs b/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaModule.cs index 35634b46d1e699..777bfb7398e2d6 100644 --- a/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaModule.cs +++ b/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaModule.cs @@ -585,7 +585,7 @@ private Object ResolveAssemblyReference(AssemblyReferenceHandle handle) an.CultureName = _metadataReader.GetString(assemblyReference.Culture); an.ContentType = GetContentTypeFromAssemblyFlags(assemblyReference.Flags); - var assembly = _moduleResolver.ResolveAssembly(an, throwIfNotFound: false); + var assembly = _moduleResolver.ResolveAssembly(an); if (assembly == null) return ResolutionFailure.GetAssemblyResolutionFailure(an.Name); else From cc878130101767986855c3d05e2bff5f7583463e Mon Sep 17 00:00:00 2001 From: Mason Wheeler Date: Thu, 30 Dec 2021 09:29:45 -0700 Subject: [PATCH 2/3] Updating PR in response to review feedback. --- src/coreclr/tools/Common/TypeSystem/Ecma/EcmaModule.cs | 2 +- .../tools/ILVerification/ILVerifyTypeSystemContext.cs | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaModule.cs b/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaModule.cs index 777bfb7398e2d6..35634b46d1e699 100644 --- a/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaModule.cs +++ b/src/coreclr/tools/Common/TypeSystem/Ecma/EcmaModule.cs @@ -585,7 +585,7 @@ private Object ResolveAssemblyReference(AssemblyReferenceHandle handle) an.CultureName = _metadataReader.GetString(assemblyReference.Culture); an.ContentType = GetContentTypeFromAssemblyFlags(assemblyReference.Flags); - var assembly = _moduleResolver.ResolveAssembly(an); + var assembly = _moduleResolver.ResolveAssembly(an, throwIfNotFound: false); if (assembly == null) return ResolutionFailure.GetAssemblyResolutionFailure(an.Name); else diff --git a/src/coreclr/tools/ILVerification/ILVerifyTypeSystemContext.cs b/src/coreclr/tools/ILVerification/ILVerifyTypeSystemContext.cs index 2a238d5c58e896..45a9b08bc10c0f 100644 --- a/src/coreclr/tools/ILVerification/ILVerifyTypeSystemContext.cs +++ b/src/coreclr/tools/ILVerification/ILVerifyTypeSystemContext.cs @@ -53,9 +53,11 @@ internal override ModuleDesc ResolveModule(IAssemblyDesc referencingModule, stri private EcmaModule ResolveAssemblyOrNetmodule(string simpleName, string verificationName, IAssemblyDesc containingAssembly, bool throwIfNotFound) { PEReader peReader = _resolver.Resolve(simpleName); - if (peReader == null && throwIfNotFound) + if (peReader == null) { - throw new VerifierException("Assembly or module not found: " + simpleName); + if (throwIfNotFound) + throw new VerifierException("Assembly or module not found: " + simpleName); + return null; } var module = GetModule(peReader, containingAssembly); VerifyModuleName(verificationName, module); From 80408b67072580cc75c224b11c25ff7b5a8e3483 Mon Sep 17 00:00:00 2001 From: Mason Wheeler Date: Fri, 31 Dec 2021 13:39:32 -0700 Subject: [PATCH 3/3] Check for CodeSizeZero error before any assumptions about code existing Fixes #63227 --- src/coreclr/tools/ILVerification/ILImporter.Verify.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/coreclr/tools/ILVerification/ILImporter.Verify.cs b/src/coreclr/tools/ILVerification/ILImporter.Verify.cs index d1b3d10ed5a3fe..c36b1361d8d47d 100644 --- a/src/coreclr/tools/ILVerification/ILImporter.Verify.cs +++ b/src/coreclr/tools/ILVerification/ILImporter.Verify.cs @@ -207,6 +207,8 @@ public ILImporter(MethodDesc method, MethodIL methodIL) public void Verify() { + FatalCheck(_ilBytes.Length > 0, VerifierError.CodeSizeZero); + _instructionBoundaries = new bool[_ilBytes.Length]; FindBasicBlocks(); @@ -284,8 +286,6 @@ private void FindEnclosingExceptionRegions() /// private void InitialPass() { - FatalCheck(_ilBytes.Length > 0, VerifierError.CodeSizeZero); - _modifiesThisPtr = false; _validTargetOffsets = new bool[_ilBytes.Length];