Bug 31225 - pedump reports invalid constructor while Microsoft's peverify reprots correct DLL
Summary: pedump reports invalid constructor while Microsoft's peverify reprots correct...
Status: RESOLVED FIXED
Alias: None
Product: Runtime
Classification: Mono
Component: Verifier ()
Version: unspecified
Hardware: Macintosh Mac OS
: --- normal
Target Milestone: ---
Assignee: Rodrigo Kumpera
URL:
Depends on:
Blocks:
 
Reported: 2015-06-18 12:04 UTC by Francisco Requena
Modified: 2017-08-21 20:09 UTC (History)
4 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:


Attachments
Test.dll and Refs.dll binaries (839 bytes, application/x-gzip)
2015-06-18 12:04 UTC, Francisco Requena
Details


Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Francisco Requena 2015-06-18 12:04:47 UTC
Created attachment 11666 [details]
Test.dll and Refs.dll binaries

I've recreated my scenario with two DLLs using Mono.Cecil 0.9.6.1 (using NuGet version). Test.dll creates a Dummy type with DummyAttribute attached to it. DummyAttribute is defined in Refs.dll. 
I'm attaching a code snippet that generates both DLLs: 

static void WriteTest ()
{
	{
		var module = ModuleDefinition.CreateModule ("Refs", ModuleKind.Dll);
		TypeDefinition type = new TypeDefinition ("Refs", "DummyAttribute", TypeAttributes.Public | TypeAttributes.Class | TypeAttributes.Serializable, module.Import (typeof(Attribute)));
		{
			MethodDefinition ctor = new MethodDefinition (".ctor", MethodAttributes.Public | MethodAttributes.HideBySig | MethodAttributes.SpecialName | MethodAttributes.RTSpecialName, module.Import (typeof(void)));
			ctor.Body.Instructions.Add (Instruction.Create (OpCodes.Ldarg_0));
			var @base = new MethodReference (".ctor", module.Import (typeof (void)), type.BaseType) { HasThis = true };
			ctor.Body.Instructions.Add (Instruction.Create (OpCodes.Call, @base));
			ctor.Body.Instructions.Add (Instruction.Create (OpCodes.Ret));
			type.Methods.Add (ctor);
		}
		module.Types.Add (type);
		module.Write ("Refs.dll");
	}

	var attr = System.Reflection.Assembly.LoadFile ("Refs.dll").GetTypes ().FirstOrDefault (t => t.Name == "DummyAttribute");

	{
		var module = ModuleDefinition.CreateModule ("Test", ModuleKind.Dll);
		TypeDefinition type = new TypeDefinition ("Test", "Dummy", TypeAttributes.Public | TypeAttributes.Class | TypeAttributes.Serializable, module.Import (typeof(object)));
		{
			MethodReference ctor = module.Import (attr.GetConstructor (Type.EmptyTypes));
			type.CustomAttributes.Add (new CustomAttribute (ctor));
		}
		module.Types.Add (type);
		module.Write ("Test.dll");
	}
}

Here's the output from pedump:

$ pedump --verify code,metadata Test.dll 
Error: Invalid CustomAttribute content row 0 Value field 0x0000000e
Error: CustomAttribute: Invalid constructor
Error count: 2

And here's the output from peverify (from version 4.0.30319.0):

All Classes and Methods in Test.dll Verified. 

Mono version: 

Mono JIT compiler version 4.0.1 ((detached/ed1d3ec Tue May 26 17:22:37 EDT 2015)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
	TLS:           normal
	SIGSEGV:       altstack
	Notification:  kqueue
	Architecture:  x86
	Disabled:      none
	Misc:          softdebug 
	LLVM:          yes(3.6.0svn-mono-(detached/a173357)
	GC:            sgen

Attaching Test.dll and Refs.dll as compiled using the code snippet above.
Comment 1 Rodrigo Kumpera 2017-08-18 22:47:22 UTC
https://github.com/mono/mono/pull/5407