[mono/mono] [2 commits] 850dd016: fixed stackoverflow exception in Attribute.GetHashCode()

"Marek Safar ([email protected])" <[email protected]> Mon, 11 Nov 2013 14:24:39 +0000
Newsgroups gmane.comp.gnome.mono.patches
Message-ID <00000142478cced7-a74f1aa4-6d69-4763-8861-38803e5127b3-000000@email.amazonses.com>
   Branch: refs/heads/master
     Home: https://github.com/mono/mono
  Compare: https://github.com/mono/mono/compare/f0094a00b517...d5f0a573ce11

   Commit: 850dd016781e523b5c80b9eb69db5a63a03b585f
   Author: xplicit <[email protected]> (xplicit)
     Date: 2013-11-11 13:44:59 GMT
      URL: https://github.com/mono/mono/commit/850dd016781e523b5c80b9eb69db5a63a03b585f

fixed stackoverflow exception in Attribute.GetHashCode()

MS implementation of Attribute.GetHashCode does not depend on TypeId property, so you can return any value in TypeId and hashcode in MS.NET will be the same.

Changed paths:
  M mcs/class/corlib/System/Attribute.cs
  M mcs/class/corlib/Test/System/AttributeTest.cs

Modified: mcs/class/corlib/System/Attribute.cs
===================================================================
@@ -258,7 +258,7 @@ public static Attribute[] GetCustomAttributes (ParameterInfo element, bool inher
 
 		public override int GetHashCode ()
 		{
-			int result = TypeId.GetHashCode ();
+			int result = GetType ().GetHashCode ();
 
 			FieldInfo[] fields = GetType ().GetFields (BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
 			foreach (FieldInfo field in fields) {

Modified: mcs/class/corlib/Test/System/AttributeTest.cs
===================================================================
@@ -88,6 +88,13 @@ public void Do ()
 		class MyDerivedClassNoAttribute : MyClass
 		{
 		}
+
+		internal class AttributeWithTypeId : Attribute
+		{
+			public override object TypeId {
+				get { return this; }
+			}
+		}
 	}
 
 	[TestFixture]
@@ -998,6 +1005,14 @@ public void NonEmptyNonOverridenGetHashCode ()
 			MyOwnCustomAttribute b1 = new MyOwnCustomAttribute (null);
 			Assert.AreNotEqual (a1.GetHashCode (), b1.GetHashCode (), "non-identical-types");
 		}
+
+		[Test]
+		public void GetHashCodeWithOverriddenTypeId ()
+		{
+			//check for not throwing stack overflow exception
+			AttributeWithTypeId a = new AttributeWithTypeId ();
+			a.GetHashCode ();
+		}
 	}
 
 	namespace ParamNamespace {

   Commit: d5f0a573ce110b75e49edd016e3dd69092812044
   Author: Marek Safar <[email protected]> (marek-safar)
     Date: 2013-11-11 14:22:35 GMT
      URL: https://github.com/mono/mono/commit/d5f0a573ce110b75e49edd016e3dd69092812044

Merge pull request #804 from xplicit/attrfix

Fixed StackOverflow exception in Attribute.GetHashCode()

Changed paths:
  M mcs/class/corlib/System/Attribute.cs
  M mcs/class/corlib/Test/System/AttributeTest.cs

Modified: mcs/class/corlib/System/Attribute.cs
===================================================================
@@ -258,7 +258,7 @@ public static Attribute[] GetCustomAttributes (ParameterInfo element, bool inher
 
 		public override int GetHashCode ()
 		{
-			int result = TypeId.GetHashCode ();
+			int result = GetType ().GetHashCode ();
 
 			FieldInfo[] fields = GetType ().GetFields (BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public);
 			foreach (FieldInfo field in fields) {

Modified: mcs/class/corlib/Test/System/AttributeTest.cs
===================================================================
@@ -88,6 +88,13 @@ public void Do ()
 		class MyDerivedClassNoAttribute : MyClass
 		{
 		}
+
+		internal class AttributeWithTypeId : Attribute
+		{
+			public override object TypeId {
+				get { return this; }
+			}
+		}
 	}
 
 	[TestFixture]
@@ -998,6 +1005,14 @@ public void NonEmptyNonOverridenGetHashCode ()
 			MyOwnCustomAttribute b1 = new MyOwnCustomAttribute (null);
 			Assert.AreNotEqual (a1.GetHashCode (), b1.GetHashCode (), "non-identical-types");
 		}
+
+		[Test]
+		public void GetHashCodeWithOverriddenTypeId ()
+		{
+			//check for not throwing stack overflow exception
+			AttributeWithTypeId a = new AttributeWithTypeId ();
+			a.GetHashCode ();
+		}
 	}
 
 	namespace ParamNamespace {


_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches