[Mono-bugs] [Bug 74928][Nor] New - TypeBuilder.CreateType causes segfaults when a method has a null parameter type

bugzilla-daemon@bugzilla.ximian.com bugzilla-daemon@bugzilla.ximian.com
Thu, 12 May 2005 22:29:02 -0400 (EDT)


Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.

Changed by dsilva@ccs.neu.edu.

http://bugzilla.ximian.com/show_bug.cgi?id=74928

--- shadow/74928	2005-05-12 22:29:02.000000000 -0400
+++ shadow/74928.tmp.10623	2005-05-12 22:29:02.000000000 -0400
@@ -0,0 +1,107 @@
+Bug#: 74928
+Product: Mono: Runtime
+Version: 1.1
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Normal
+Component: misc
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: dsilva@ccs.neu.edu               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: TypeBuilder.CreateType causes segfaults when a method has a null parameter type
+
+Description of Problem:
+
+TypeBuilder.CreateType may only throw two exceptions,
+InvalidOperationException or NotSupportedException.  The cases for each
+exception are outlined in
+http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemreflectionemittypebuilderclasscreatetypetopic.asp
+
+One case it does not outline is where a method has "null" as a parameter
+type.  This omission looks like a bug in the .Net framework, specifically
+in the contract for TypeBuilder.CreateType or for TypeBuilder.DefineMethod,
+whose documentation is also silent on this case:
+http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemreflectionemittypebuilderclassdefinemethodtopic1.asp
+
+The case makes the mono runtime segfault under gdb, though the segfault is
+converted into a NullReferenceException when running without gdb.
+ 
+Sample program:
+
+
+using System;
+using System.Reflection;
+using System.Reflection.Emit;
+
+class ReflectionTest {
+  public static void Main(string[] args) {
+    AssemblyName assemblyName = new AssemblyName();
+    assemblyName.Name = "MyDynamicAssembly";
+    const string outfile = "testout.exe";
+    AssemblyBuilder newAsm
+                     = AppDomain.
+                        CurrentDomain.
+                         DefineDynamicAssembly(assemblyName,
+                                               AssemblyBuilderAccess.Save);
+    ModuleBuilder newModule
+                   = newAsm.DefineDynamicModule("MyModule",
+                                               outfile,
+                                                 true);
+    TypeBuilder newType
+                 = newModule.DefineType("MyType", TypeAttributes.Public);
+
+    MethodBuilder newMethod
+                   = newType.DefineMethod("m",
+                                          MethodAttributes.Public,
+                                          typeof(void),
+                                          new Type[] {null}); // <-HERE
+
+    newType.CreateType();
+  }
+}
+
+
+Running with extra printfs in reflection.c and in NullReferenceException's
+constructor:
+
+$ mono ReflectionTest.exe
+reflection.c:ctorbuilder_to_mono_method: .ctor
+reflection.c:parameters_to_signature: count = 0
+reflection.c:reflection_methodbuilder_to_mono_method: .ctor
+reflection.c:methodbuilder_to_mono_method: m
+reflection.c:parameters_to_signature: count = 1
+reflection.c:  sig: 0x83b68b8, pt: 0x0
+
+         at System.NullReferenceException..ctor ()
+         at System.Reflection.Emit.TypeBuilder.create_runtime_class ()
+         at System.Reflection.Emit.TypeBuilder.create_runtime_class ()
+         at System.Reflection.Emit.TypeBuilder.CreateType ()
+         at ReflectionTest.Main ()
+
+Unhandled Exception: System.NullReferenceException: Object reference not
+set to an instance of an object
+in <0x00000> <unknown method>
+in (wrapper managed-to-native)
+System.Reflection.Emit.TypeBuilder:create_runtime_class
+(System.Reflection.Emit.TypeBuilder)
+in <0x00264> System.Reflection.Emit.TypeBuilder:CreateType ()
+in <0x000f4> ReflectionTest:Main (System.String[] args)
+
+
+Running with gdb mono:
+
+$ gdb mono
+...
+(gdb) run ReflectionTest.exe
+...
+Program received signal SIGSEGV, Segmentation fault.
+[Switching to Thread -1210247488 (LWP 4137)]
+methodbuilder_to_mono_method (klass=0x837c2d8, mb=0x833cd90) at
+reflection.c:7011
+7011                    sig->params [i] = pt->type;