[Mono-bugs] [Bug 79744][Min] New - Invalid code that breaks the runtime.

bugzilla-daemon at bugzilla.ximian.com bugzilla-daemon at bugzilla.ximian.com
Thu Oct 26 14:05:51 EDT 2006


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 miguel at ximian.com.

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

--- shadow/79744	2006-10-26 14:05:51.000000000 -0400
+++ shadow/79744.tmp.27028	2006-10-26 14:05:51.000000000 -0400
@@ -0,0 +1,63 @@
+Bug#: 79744
+Product: Mono: Runtime
+Version: 1.1
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Minor
+Component: JIT
+AssignedTo: lupus at ximian.com                            
+ReportedBy: miguel at ximian.com               
+QAContact: mono-bugs at ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Invalid code that breaks the runtime.
+
+Code that uses unaligned offsets for objects can break the runtime, we
+should instead throw a TypeLoadException:
+
+using System;
+using System.Runtime.InteropServices;
+
+public class Z {
+    ~Z() {
+        Console.WriteLine("Hello, world!");
+    }
+}
+
+[StructLayout(LayoutKind.Explicit)]
+public struct X {
+    [FieldOffset(0)] public short a;
+    [FieldOffset(2)] public Z z; // Unaligned reference
+}
+
+class Y {
+    static X test() {
+        X x = new X();
+        x.z = new Z();
+        return x;
+    }
+
+    static void test2(X x) {
+        Console.WriteLine("Object: " + x);
+    }
+
+    static void Main() {
+        X t1 = test();
+        System.GC.Collect();
+        System.GC.Collect();
+        System.GC.WaitForPendingFinalizers();
+        test2(t1);
+    }
+}
+
+MS results:
+
+Unhandled Exception: System.TypeLoadException: Could not load type X from
+assembly a, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null because
+it contains an object field at offset 2 that is incorrectly aligned or
+overlapped by a non-object field.
+   at Y.Main()


More information about the mono-bugs mailing list