Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore strongname mismatch for assemblies returned by AssemblyResolve event #101039

Merged
merged 2 commits into from
Apr 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/coreclr/dlls/mscorrc/mscorrc.rc
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ BEGIN
COR_E_FILELOAD "Unable to load file '%1'."
COR_E_ASSEMBLYEXPECTED "The module '%1' was expected to contain an assembly manifest."
FUSION_E_REF_DEF_MISMATCH "The located assembly's manifest definition with name '%1' does not match the assembly reference."
FUSION_E_PRIVATE_ASM_DISALLOWED "Assembly '%1' is required to be strongly named."
FUSION_E_INVALID_NAME "The given assembly name, '%1', was invalid."
FUSION_E_APP_DOMAIN_LOCKED "The requested assembly version conflicts with what is already bound in the app domain or specified in the manifest."
IDS_EE_HASH_VAL_FAILED "Hash validation failed for file or assembly '%1'."
Expand Down
6 changes: 0 additions & 6 deletions src/coreclr/inc/corerror.xml
Original file line number Diff line number Diff line change
Expand Up @@ -172,12 +172,6 @@
<Comment> The located assembly's manifest definition does not match the assembly reference. </Comment>
</HRESULT>

<HRESULT NumericValue="0x80131044">
<SymbolicName>FUSION_E_PRIVATE_ASM_DISALLOWED</SymbolicName>
<Message>"A strongly-named assembly is required."</Message>
<Comment> A strongly-named assembly is required. </Comment>
</HRESULT>

<HRESULT NumericValue="0x80131047">
<SymbolicName>FUSION_E_INVALID_NAME</SymbolicName>
<Message>"The given assembly name was invalid."</Message>
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/pal/prebuilt/corerror/mscorurt.rc
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ BEGIN
MSG_FOR_URT_HR(HOST_E_INVALIDOPERATION) "Invalid operation."
MSG_FOR_URT_HR(HOST_E_CLRNOTAVAILABLE) "CLR has been disabled due to unrecoverable error."
MSG_FOR_URT_HR(FUSION_E_REF_DEF_MISMATCH) "The located assembly's manifest definition does not match the assembly reference."
MSG_FOR_URT_HR(FUSION_E_PRIVATE_ASM_DISALLOWED) "A strongly-named assembly is required."
MSG_FOR_URT_HR(FUSION_E_INVALID_NAME) "The given assembly name was invalid."
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."
MSG_FOR_URT_HR(COR_E_LOADING_REFERENCE_ASSEMBLY) "Reference assemblies cannot be loaded for execution."
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/pal/prebuilt/inc/corerror.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
#define HOST_E_INVALIDOPERATION EMAKEHR(0x1022)
#define HOST_E_CLRNOTAVAILABLE EMAKEHR(0x1023)
#define FUSION_E_REF_DEF_MISMATCH EMAKEHR(0x1040)
#define FUSION_E_PRIVATE_ASM_DISALLOWED EMAKEHR(0x1044)
#define FUSION_E_INVALID_NAME EMAKEHR(0x1047)
#define FUSION_E_APP_DOMAIN_LOCKED EMAKEHR(0x1053)
#define COR_E_LOADING_REFERENCE_ASSEMBLY EMAKEHR(0x1058)
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/utilcode/ex.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,6 @@ LPCSTR Exception::GetHRSymbolicName(HRESULT hr)
CASE_HRESULT(COR_E_CANNOTUNLOADAPPDOMAIN)
CASE_HRESULT(MSEE_E_ASSEMBLYLOADINPROGRESS)
CASE_HRESULT(FUSION_E_REF_DEF_MISMATCH)
CASE_HRESULT(FUSION_E_PRIVATE_ASM_DISALLOWED)
CASE_HRESULT(FUSION_E_INVALID_NAME)
CASE_HRESULT(CLDB_E_FILE_BADREAD)
CASE_HRESULT(CLDB_E_FILE_BADWRITE)
Expand Down
7 changes: 0 additions & 7 deletions src/coreclr/vm/appdomain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4528,13 +4528,6 @@ AppDomain::RaiseAssemblyResolveEvent(
}
GCPROTECT_END();

if (pAssembly != NULL)
{
// Check that the public key token matches the one specified in the spec
// MatchPublicKeys throws as appropriate
pSpec->MatchPublicKeys(pAssembly);
}

RETURN pAssembly;
} // AppDomain::RaiseAssemblyResolveEvent

Expand Down
49 changes: 0 additions & 49 deletions src/coreclr/vm/assemblyspec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -295,55 +295,6 @@ void AssemblySpec::InitializeAssemblyNameRef(_In_ BINDER_SPACE::AssemblyName* as
spec.AssemblyNameInit(assemblyNameRef);
}


// Check if the supplied assembly's public key matches up with the one in the Spec, if any
// Throws an appropriate exception in case of a mismatch
void AssemblySpec::MatchPublicKeys(Assembly *pAssembly)
{
CONTRACTL
{
INSTANCE_CHECK;
THROWS;
GC_TRIGGERS;
MODE_ANY;
}
CONTRACTL_END;

// Check that the public keys are the same as in the AR.
if (!IsStrongNamed())
return;

const void *pbPublicKey;
DWORD cbPublicKey;
pbPublicKey = pAssembly->GetPublicKey(&cbPublicKey);
if (cbPublicKey == 0)
ThrowHR(FUSION_E_PRIVATE_ASM_DISALLOWED);

if (IsAfPublicKey(m_dwFlags))
{
if ((m_cbPublicKeyOrToken != cbPublicKey) ||
memcmp(m_pbPublicKeyOrToken, pbPublicKey, m_cbPublicKeyOrToken))
{
ThrowHR(FUSION_E_REF_DEF_MISMATCH);
}
}
else
{
// Ref has a token
StrongNameToken strongNameToken;

IfFailThrow(StrongNameTokenFromPublicKey((BYTE*)pbPublicKey,
cbPublicKey,
&strongNameToken));

if ((m_cbPublicKeyOrToken != StrongNameToken::SIZEOF_TOKEN) ||
memcmp(m_pbPublicKeyOrToken, &strongNameToken, StrongNameToken::SIZEOF_TOKEN))
{
ThrowHR(FUSION_E_REF_DEF_MISMATCH);
}
}
}

Assembly *AssemblySpec::LoadAssembly(FileLoadLevel targetLevel, BOOL fThrowOnFileNotFound)
{
CONTRACTL
Expand Down
2 changes: 0 additions & 2 deletions src/coreclr/vm/assemblyspec.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,6 @@ class AssemblySpec : public BaseAssemblySpec
static void InitializeAssemblyNameRef(_In_ BINDER_SPACE::AssemblyName* assemblyName, _Out_ ASSEMBLYNAMEREF* assemblyNameRef);

public:
void MatchPublicKeys(Assembly *pAssembly);

AppDomain *GetAppDomain()
{
LIMITED_METHOD_CONTRACT;
Expand Down
1 change: 0 additions & 1 deletion src/coreclr/vm/rexcep.h
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ DEFINE_EXCEPTION(g_SystemNS, FieldAccessException, false, C
DEFINE_EXCEPTION(g_IONS, FileLoadException, true,
COR_E_FILELOAD,
FUSION_E_INVALID_NAME,
FUSION_E_PRIVATE_ASM_DISALLOWED,
FUSION_E_REF_DEF_MISMATCH,
HRESULT_FROM_WIN32(ERROR_TOO_MANY_OPEN_FILES),
HRESULT_FROM_WIN32(ERROR_SHARING_VIOLATION), HRESULT_FROM_WIN32(ERROR_LOCK_VIOLATION),
Expand Down
1 change: 0 additions & 1 deletion src/libraries/Common/src/System/HResults.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,6 @@ internal static partial class HResults
internal const int CTL_E_PATHNOTFOUND = unchecked((int)0x800A004C);
internal const int CTL_E_FILENOTFOUND = unchecked((int)0x800A0035);
internal const int FUSION_E_INVALID_NAME = unchecked((int)0x80131047);
internal const int FUSION_E_PRIVATE_ASM_DISALLOWED = unchecked((int)0x80131044);
internal const int FUSION_E_REF_DEF_MISMATCH = unchecked((int)0x80131040);
internal const int ERROR_TOO_MANY_OPEN_FILES = unchecked((int)0x80070004);
internal const int ERROR_SHARING_VIOLATION = unchecked((int)0x80070020);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -818,7 +818,6 @@ public static IntPtr GetHINSTANCE(Module m)
};
}
case HResults.FUSION_E_INVALID_NAME:
case HResults.FUSION_E_PRIVATE_ASM_DISALLOWED:
case HResults.FUSION_E_REF_DEF_MISMATCH:
case HResults.ERROR_TOO_MANY_OPEN_FILES:
case HResults.ERROR_SHARING_VIOLATION:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.IO;
using System.Net.Http;
using System.Reflection;
using System.Reflection.Emit;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.ExceptionServices;
Expand Down Expand Up @@ -654,6 +655,24 @@ public void AssemblyResolve_IsNotCalledForCoreLibResources()
}).Dispose();
}

[ConditionalFact(typeof(RemoteExecutor), nameof(RemoteExecutor.IsSupported))]
public void AssemblyResolve_IgnoresStrongNameMismatches()
{
RemoteExecutor.Invoke(() =>
{
AppDomain.CurrentDomain.AssemblyResolve +=
(sender, e) =>
{
if (!e.Name.StartsWith("MyAssembly"))
return null;

return AssemblyBuilder.DefineDynamicAssembly(
new AssemblyName("MyAssembly"), AssemblyBuilderAccess.Run);
};
Assembly.Load("MyAssembly, PublicKeyToken=1234567890ABCDEF");
}).Dispose();
}

class CorrectlyPropagatesException : Exception
{
public CorrectlyPropagatesException(string message) : base(message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public static class HResults

public const int COR_E_FILELOAD = unchecked((int)0x80131621);
public const int FUSION_E_INVALID_NAME = unchecked((int)0x80131047);
public const int FUSION_E_PRIVATE_ASM_DISALLOWED = unchecked((int)0x80131044);
public const int FUSION_E_REF_DEF_MISMATCH = unchecked((int)0x80131040);
public const int ERROR_TOO_MANY_OPEN_FILES = unchecked((int)0x80070004);
public const int ERROR_SHARING_VIOLATION = unchecked((int)0x80070020);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ public static class FileLoadExceptionInteropTests
[Theory]
[InlineData(HResults.COR_E_FILELOAD)]
[InlineData(HResults.FUSION_E_INVALID_NAME)]
[InlineData(HResults.FUSION_E_PRIVATE_ASM_DISALLOWED)]
[InlineData(HResults.FUSION_E_REF_DEF_MISMATCH)]
[InlineData(HResults.ERROR_TOO_MANY_OPEN_FILES)]
[InlineData(HResults.ERROR_SHARING_VIOLATION)]
Expand Down
Loading