Skip to content

Commit 081e28f

Browse files
jkotasRuihan-Yin
authored andcommitted
Ignore strongname mismatch for assemblies returned by AssemblyResolve event (dotnet#101039)
This check was somehow missed during earlier cleanups that deleted strongname matching for assembly binding. Fixes dotnet#101029
1 parent ed5c5db commit 081e28f

File tree

14 files changed

+19
-73
lines changed

14 files changed

+19
-73
lines changed

src/coreclr/dlls/mscorrc/mscorrc.rc

-1
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,6 @@ BEGIN
113113
COR_E_FILELOAD "Unable to load file '%1'."
114114
COR_E_ASSEMBLYEXPECTED "The module '%1' was expected to contain an assembly manifest."
115115
FUSION_E_REF_DEF_MISMATCH "The located assembly's manifest definition with name '%1' does not match the assembly reference."
116-
FUSION_E_PRIVATE_ASM_DISALLOWED "Assembly '%1' is required to be strongly named."
117116
FUSION_E_INVALID_NAME "The given assembly name, '%1', was invalid."
118117
FUSION_E_APP_DOMAIN_LOCKED "The requested assembly version conflicts with what is already bound in the app domain or specified in the manifest."
119118
IDS_EE_HASH_VAL_FAILED "Hash validation failed for file or assembly '%1'."

src/coreclr/inc/corerror.xml

-6
Original file line numberDiff line numberDiff line change
@@ -172,12 +172,6 @@
172172
<Comment> The located assembly's manifest definition does not match the assembly reference. </Comment>
173173
</HRESULT>
174174

175-
<HRESULT NumericValue="0x80131044">
176-
<SymbolicName>FUSION_E_PRIVATE_ASM_DISALLOWED</SymbolicName>
177-
<Message>"A strongly-named assembly is required."</Message>
178-
<Comment> A strongly-named assembly is required. </Comment>
179-
</HRESULT>
180-
181175
<HRESULT NumericValue="0x80131047">
182176
<SymbolicName>FUSION_E_INVALID_NAME</SymbolicName>
183177
<Message>"The given assembly name was invalid."</Message>

src/coreclr/pal/prebuilt/corerror/mscorurt.rc

-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ BEGIN
1414
MSG_FOR_URT_HR(HOST_E_INVALIDOPERATION) "Invalid operation."
1515
MSG_FOR_URT_HR(HOST_E_CLRNOTAVAILABLE) "CLR has been disabled due to unrecoverable error."
1616
MSG_FOR_URT_HR(FUSION_E_REF_DEF_MISMATCH) "The located assembly's manifest definition does not match the assembly reference."
17-
MSG_FOR_URT_HR(FUSION_E_PRIVATE_ASM_DISALLOWED) "A strongly-named assembly is required."
1817
MSG_FOR_URT_HR(FUSION_E_INVALID_NAME) "The given assembly name was invalid."
1918
MSG_FOR_URT_HR(FUSION_E_APP_DOMAIN_LOCKED) "The requested assembly version conflicts with what is already bound in the app domain or specified in the manifest."
2019
MSG_FOR_URT_HR(COR_E_LOADING_REFERENCE_ASSEMBLY) "Reference assemblies cannot be loaded for execution."

src/coreclr/pal/prebuilt/inc/corerror.h

-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
#define HOST_E_INVALIDOPERATION EMAKEHR(0x1022)
4242
#define HOST_E_CLRNOTAVAILABLE EMAKEHR(0x1023)
4343
#define FUSION_E_REF_DEF_MISMATCH EMAKEHR(0x1040)
44-
#define FUSION_E_PRIVATE_ASM_DISALLOWED EMAKEHR(0x1044)
4544
#define FUSION_E_INVALID_NAME EMAKEHR(0x1047)
4645
#define FUSION_E_APP_DOMAIN_LOCKED EMAKEHR(0x1053)
4746
#define COR_E_LOADING_REFERENCE_ASSEMBLY EMAKEHR(0x1058)

src/coreclr/utilcode/ex.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,6 @@ LPCSTR Exception::GetHRSymbolicName(HRESULT hr)
574574
CASE_HRESULT(COR_E_CANNOTUNLOADAPPDOMAIN)
575575
CASE_HRESULT(MSEE_E_ASSEMBLYLOADINPROGRESS)
576576
CASE_HRESULT(FUSION_E_REF_DEF_MISMATCH)
577-
CASE_HRESULT(FUSION_E_PRIVATE_ASM_DISALLOWED)
578577
CASE_HRESULT(FUSION_E_INVALID_NAME)
579578
CASE_HRESULT(CLDB_E_FILE_BADREAD)
580579
CASE_HRESULT(CLDB_E_FILE_BADWRITE)

src/coreclr/vm/appdomain.cpp

-7
Original file line numberDiff line numberDiff line change
@@ -4528,13 +4528,6 @@ AppDomain::RaiseAssemblyResolveEvent(
45284528
}
45294529
GCPROTECT_END();
45304530

4531-
if (pAssembly != NULL)
4532-
{
4533-
// Check that the public key token matches the one specified in the spec
4534-
// MatchPublicKeys throws as appropriate
4535-
pSpec->MatchPublicKeys(pAssembly);
4536-
}
4537-
45384531
RETURN pAssembly;
45394532
} // AppDomain::RaiseAssemblyResolveEvent
45404533

src/coreclr/vm/assemblyspec.cpp

-49
Original file line numberDiff line numberDiff line change
@@ -295,55 +295,6 @@ void AssemblySpec::InitializeAssemblyNameRef(_In_ BINDER_SPACE::AssemblyName* as
295295
spec.AssemblyNameInit(assemblyNameRef);
296296
}
297297

298-
299-
// Check if the supplied assembly's public key matches up with the one in the Spec, if any
300-
// Throws an appropriate exception in case of a mismatch
301-
void AssemblySpec::MatchPublicKeys(Assembly *pAssembly)
302-
{
303-
CONTRACTL
304-
{
305-
INSTANCE_CHECK;
306-
THROWS;
307-
GC_TRIGGERS;
308-
MODE_ANY;
309-
}
310-
CONTRACTL_END;
311-
312-
// Check that the public keys are the same as in the AR.
313-
if (!IsStrongNamed())
314-
return;
315-
316-
const void *pbPublicKey;
317-
DWORD cbPublicKey;
318-
pbPublicKey = pAssembly->GetPublicKey(&cbPublicKey);
319-
if (cbPublicKey == 0)
320-
ThrowHR(FUSION_E_PRIVATE_ASM_DISALLOWED);
321-
322-
if (IsAfPublicKey(m_dwFlags))
323-
{
324-
if ((m_cbPublicKeyOrToken != cbPublicKey) ||
325-
memcmp(m_pbPublicKeyOrToken, pbPublicKey, m_cbPublicKeyOrToken))
326-
{
327-
ThrowHR(FUSION_E_REF_DEF_MISMATCH);
328-
}
329-
}
330-
else
331-
{
332-
// Ref has a token
333-
StrongNameToken strongNameToken;
334-
335-
IfFailThrow(StrongNameTokenFromPublicKey((BYTE*)pbPublicKey,
336-
cbPublicKey,
337-
&strongNameToken));
338-
339-
if ((m_cbPublicKeyOrToken != StrongNameToken::SIZEOF_TOKEN) ||
340-
memcmp(m_pbPublicKeyOrToken, &strongNameToken, StrongNameToken::SIZEOF_TOKEN))
341-
{
342-
ThrowHR(FUSION_E_REF_DEF_MISMATCH);
343-
}
344-
}
345-
}
346-
347298
Assembly *AssemblySpec::LoadAssembly(FileLoadLevel targetLevel, BOOL fThrowOnFileNotFound)
348299
{
349300
CONTRACTL

src/coreclr/vm/assemblyspec.hpp

-2
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,6 @@ class AssemblySpec : public BaseAssemblySpec
193193
static void InitializeAssemblyNameRef(_In_ BINDER_SPACE::AssemblyName* assemblyName, _Out_ ASSEMBLYNAMEREF* assemblyNameRef);
194194

195195
public:
196-
void MatchPublicKeys(Assembly *pAssembly);
197-
198196
AppDomain *GetAppDomain()
199197
{
200198
LIMITED_METHOD_CONTRACT;

src/coreclr/vm/rexcep.h

-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ DEFINE_EXCEPTION(g_SystemNS, FieldAccessException, false, C
144144
DEFINE_EXCEPTION(g_IONS, FileLoadException, true,
145145
COR_E_FILELOAD,
146146
FUSION_E_INVALID_NAME,
147-
FUSION_E_PRIVATE_ASM_DISALLOWED,
148147
FUSION_E_REF_DEF_MISMATCH,
149148
HRESULT_FROM_WIN32(ERROR_TOO_MANY_OPEN_FILES),
150149
HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION), HRESULT_FROM_WIN32(ERROR_LOCK_VIOLATION),

src/libraries/Common/src/System/HResults.cs

-1
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,6 @@ internal static partial class HResults
127127
internal const int CTL_E_PATHNOTFOUND = unchecked((int)0x800A004C);
128128
internal const int CTL_E_FILENOTFOUND = unchecked((int)0x800A0035);
129129
internal const int FUSION_E_INVALID_NAME = unchecked((int)0x80131047);
130-
internal const int FUSION_E_PRIVATE_ASM_DISALLOWED = unchecked((int)0x80131044);
131130
internal const int FUSION_E_REF_DEF_MISMATCH = unchecked((int)0x80131040);
132131
internal const int ERROR_TOO_MANY_OPEN_FILES = unchecked((int)0x80070004);
133132
internal const int ERROR_SHARING_VIOLATION = unchecked((int)0x80070020);

src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs

-1
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,6 @@ public static IntPtr GetHINSTANCE(Module m)
818818
};
819819
}
820820
case HResults.FUSION_E_INVALID_NAME:
821-
case HResults.FUSION_E_PRIVATE_ASM_DISALLOWED:
822821
case HResults.FUSION_E_REF_DEF_MISMATCH:
823822
case HResults.ERROR_TOO_MANY_OPEN_FILES:
824823
case HResults.ERROR_SHARING_VIOLATION:

src/libraries/System.Runtime/tests/System.Runtime.Extensions.Tests/System/AppDomainTests.cs

+19
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using System.IO;
88
using System.Net.Http;
99
using System.Reflection;
10+
using System.Reflection.Emit;
1011
using System.Resources;
1112
using System.Runtime.CompilerServices;
1213
using System.Runtime.ExceptionServices;
@@ -654,6 +655,24 @@ public void AssemblyResolve_IsNotCalledForCoreLibResources()
654655
}).Dispose();
655656
}
656657

658+
[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
659+
public void AssemblyResolve_IgnoresStrongNameMismatches()
660+
{
661+
RemoteExecutor.Invoke(() =>
662+
{
663+
AppDomain.CurrentDomain.AssemblyResolve +=
664+
(sender, e) =>
665+
{
666+
if (!e.Name.StartsWith("MyAssembly"))
667+
return null;
668+
669+
return AssemblyBuilder.DefineDynamicAssembly(
670+
new AssemblyName("MyAssembly"), AssemblyBuilderAccess.Run);
671+
};
672+
Assembly.Load("MyAssembly, PublicKeyToken=1234567890ABCDEF");
673+
}).Dispose();
674+
}
675+
657676
class CorrectlyPropagatesException : Exception
658677
{
659678
public CorrectlyPropagatesException(string message) : base(message)

src/libraries/System.Runtime/tests/System.Runtime.Tests/System/IO/Exceptions.HResults.cs

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ public static class HResults
1818

1919
public const int COR_E_FILELOAD = unchecked((int)0x80131621);
2020
public const int FUSION_E_INVALID_NAME = unchecked((int)0x80131047);
21-
public const int FUSION_E_PRIVATE_ASM_DISALLOWED = unchecked((int)0x80131044);
2221
public const int FUSION_E_REF_DEF_MISMATCH = unchecked((int)0x80131040);
2322
public const int ERROR_TOO_MANY_OPEN_FILES = unchecked((int)0x80070004);
2423
public const int ERROR_SHARING_VIOLATION = unchecked((int)0x80070020);

src/libraries/System.Runtime/tests/System.Runtime.Tests/System/IO/FileLoadException.InteropTests.cs

-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ public static class FileLoadExceptionInteropTests
1313
[Theory]
1414
[InlineData(HResults.COR_E_FILELOAD)]
1515
[InlineData(HResults.FUSION_E_INVALID_NAME)]
16-
[InlineData(HResults.FUSION_E_PRIVATE_ASM_DISALLOWED)]
1716
[InlineData(HResults.FUSION_E_REF_DEF_MISMATCH)]
1817
[InlineData(HResults.ERROR_TOO_MANY_OPEN_FILES)]
1918
[InlineData(HResults.ERROR_SHARING_VIOLATION)]

0 commit comments

Comments
 (0)