[Mono-bugs] [Bug 35140][Wis] New - Mono runtime allows objects of incompatible types to be assigned to arrays.

bugzilla-daemon@rocky.ximian.com bugzilla-daemon@rocky.ximian.com
5 Dec 2002 15:39:10 -0000


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 tum@veridicus.com.

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

--- shadow/35140	Thu Dec  5 10:39:10 2002
+++ shadow/35140.tmp.18275	Thu Dec  5 10:39:10 2002
@@ -0,0 +1,103 @@
+Bug#: 35140
+Product: Mono/Runtime
+Version: unspecified
+OS: 
+OS Details: 
+Status: NEW   
+Resolution: 
+Severity: 
+Priority: Wishlist
+Component: misc
+AssignedTo: mono-bugs@ximian.com                            
+ReportedBy: tum@veridicus.com               
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL: 
+Cc: 
+Summary: Mono runtime allows objects of incompatible types to be assigned to arrays.
+
+Please fill in this template when reporting a bug, unless you know what 
+you are doing.
+Description of Problem:
+
+The runtime doesn't dynamically validate that an object assigned to an 
+array is of (or is derived from) the same type as the array's element 
+type.  The runtime shouldn't rely on static type verification done by the 
+compiler. 
+
+Steps to reproduce the problem:
+
+Compile and run the following program.
+
+---begin-testarraytyping.cs--
+
+using System;
+using System.IO;
+using System.Collections;
+using System.Threading;
+
+class Test
+{
+	public abstract class Animal
+	{		
+	}
+
+	public class Dog
+		: Animal
+	{		
+	}
+
+	public class Cat
+		: Animal
+	{
+		public Cat()
+		{		
+		}
+
+		public void Purr()
+		{
+			Console.WriteLine("Purr");
+		}
+	}
+
+	public static void Foo(Animal[] animal)
+	{
+		// Should throw ArrayTypeMismatchException
+
+		animal[0] = new Dog();
+	}
+
+	static void Main()
+	{
+		Cat[] cats = new Cat[10];
+
+		cats[0] = new Cat();
+
+		Foo(cats);
+
+                // cats[0] is now a dog (dogs can't purr).
+		cats[0].Purr();
+	}
+}
+
+---end-testarraytyping.cs--
+
+Actual Results:
+
+The program compiles file (it should, it is valid C#).  When run, the 
+program incorrectly prints "Purr".  This could potentially cause 
+corruption of memory because you can call methods that don't exist.
+
+Expected Results:
+
+The program when run should fail with an ArrayTypeMismatchException at 
+the line "animal[0] = new Dog();"
+
+How often does this happen? 
+
+All the time.
+
+Additional Information:
+
+Microsoft's runtime correctly throws an exception.  The JIT and 
+mono_array_set (from metadata/object.h) will need to be changed.