Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 207515e

Browse files
author
Koundinya Veluri
authored
Don't call AssemblyResolve event for CoreLib resources (#12999) (#13003)
Don't call AssemblyResolve event for CoreLib resources Part of fix for #12668: - CoreLib resource lookup should not raise the AssemblyResolve event because a misbehaving handler could cause an infinite recursion check and fail-fast to be triggered when the resource is not found, as the issue would repeat when reporting that error - A handler could misbehave by returning an assembly that does not match the requested identity or by throwing
1 parent 94d4aa4 commit 207515e

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

src/mscorlib/src/System/Reflection/Assembly.CoreCLR.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@ public abstract partial class Assembly : ICustomAttributeProvider, ISerializable
2323
private static Assembly LoadFromResolveHandler(object sender, ResolveEventArgs args)
2424
{
2525
Assembly requestingAssembly = args.RequestingAssembly;
26-
26+
if (requestingAssembly == null)
27+
{
28+
return null;
29+
}
30+
2731
// Requesting assembly for LoadFrom is always loaded in defaultContext - proceed only if that
2832
// is the case.
2933
if (AssemblyLoadContext.Default != AssemblyLoadContext.GetLoadContext(requestingAssembly))

src/vm/appdomain.cpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7220,18 +7220,26 @@ EndTry2:;
72207220
}
72217221
else if (!fIsWellKnown)
72227222
{
7223-
// Trigger the resolve event also for non-throw situation.
7224-
// However, this code path will behave as if the resolve handler has thrown,
7225-
// that is, not trigger an MDA.
72267223
_ASSERTE(fThrowOnFileNotFound == FALSE);
72277224

7228-
AssemblySpec NewSpec(this);
7229-
AssemblySpec *pFailedSpec = NULL;
7225+
// Don't trigger the resolve event for the CoreLib satellite assembly. A misbehaving resolve event may
7226+
// return an assembly that does not match, and this can cause recursive resource lookups during error
7227+
// reporting. The CoreLib satellite assembly is loaded from relative locations based on the culture, see
7228+
// AssemblySpec::Bind().
7229+
if (!pSpec->IsMscorlibSatellite())
7230+
{
7231+
// Trigger the resolve event also for non-throw situation.
7232+
// However, this code path will behave as if the resolve handler has thrown,
7233+
// that is, not trigger an MDA.
7234+
7235+
AssemblySpec NewSpec(this);
7236+
AssemblySpec *pFailedSpec = NULL;
72307237

7231-
fForceReThrow = TRUE; // Managed resolve event handler can throw
7238+
fForceReThrow = TRUE; // Managed resolve event handler can throw
72327239

7233-
// Purposly ignore return value
7234-
PostBindResolveAssembly(pSpec, &NewSpec, hrBindResult, &pFailedSpec);
7240+
// Purposly ignore return value
7241+
PostBindResolveAssembly(pSpec, &NewSpec, hrBindResult, &pFailedSpec);
7242+
}
72357243
}
72367244
}
72377245
}

0 commit comments

Comments
 (0)