Skip to content

Commit

Permalink
[loader] Don't try to look for ReferenceAssemblyAttribute on dynamic …
Browse files Browse the repository at this point in the history
…assemblies (Fixes #57851)

.NETFramework seems to ignore this custom attribute and allows instantiating
types from on assembly builders.
  • Loading branch information
lambdageek committed Jun 30, 2017
1 parent fa6194c commit 225848b
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
11 changes: 9 additions & 2 deletions mono/metadata/assembly.c
Expand Up @@ -2108,6 +2108,10 @@ has_reference_assembly_attribute_iterator (MonoImage *image, guint32 typeref_sco
gboolean
mono_assembly_has_reference_assembly_attribute (MonoAssembly *assembly, MonoError *error)
{
g_assert (assembly && assembly->image);
/* .NET Framework appears to ignore the attribute on dynamic
* assemblies, so don't call this function for dynamic assemblies. */
g_assert (!image_is_dynamic (assembly->image));
error_init (error);

/*
Expand Down Expand Up @@ -3513,8 +3517,11 @@ prevent_reference_assembly_from_running (MonoAssembly* candidate, gboolean refon
{
MonoError refasm_error;
error_init (&refasm_error);
if (candidate && !refonly && mono_assembly_has_reference_assembly_attribute (candidate, &refasm_error)) {
candidate = NULL;
if (candidate && !refonly) {
/* .NET Framework seems to not check for ReferenceAssemblyAttribute on dynamic assemblies */
if (!image_is_dynamic (candidate->image) &&
mono_assembly_has_reference_assembly_attribute (candidate, &refasm_error))
candidate = NULL;
}
mono_error_cleanup (&refasm_error);
return candidate;
Expand Down
3 changes: 3 additions & 0 deletions mono/metadata/custom-attrs.c
Expand Up @@ -1950,6 +1950,9 @@ mono_assembly_metadata_foreach_custom_attr (MonoAssembly *assembly, MonoAssembly
*/

image = assembly->image;
/* Dynamic images would need to go through the AssemblyBuilder's
* CustomAttributeBuilder array. Going through the tables below
* definitely won't work. */
g_assert (!image_is_dynamic (image));
idx = 1; /* there is only one assembly */
idx <<= MONO_CUSTOM_ATTR_BITS;
Expand Down

0 comments on commit 225848b

Please sign in to comment.