Revert "Fix array allocation bounds checking."
authorAditya Mandaleeka <adityam@microsoft.com>
Tue, 3 May 2016 23:49:13 +0000 (16:49 -0700)
committerAditya Mandaleeka <adityam@microsoft.com>
Tue, 3 May 2016 23:49:13 +0000 (16:49 -0700)
This reverts commit 16c9dfbae5e5ce18ad0519b31df515820fed2579.

src/vm/gchelpers.cpp

index 9b77b0ed96732efe6a2a8b1ee54c1ab6df6f4652..bf81847716778af5218523fc05434dbc2ef66efc 100644 (file)
@@ -350,28 +350,13 @@ OBJECTREF AllocateArrayEx(TypeHandle arrayType, INT32 *pArgs, DWORD dwNumArgs, B
                 lowerBound = pArgs[i];
                 i++;
             }
-
             int length = pArgs[i];
             if (length < 0)
                 COMPlusThrow(kOverflowException);
-
             if ((SIZE_T)length > MaxArrayLength(componentSize))
-            {
-                // This will cause us to throw below if we don't throw anything else before then.
                 maxArrayDimensionLengthOverflow = true;
-            }
-
-            if (length > 0)
-            {
-                int highestAllowableLowerBound = INT32_MAX - (length - 1);
-                if (lowerBound > highestAllowableLowerBound)
-                {
-                    // We throw because the lower bound is large enough that the sum of the 
-                    // dimension's length and the lower bound would exceed INT32_MAX.
-                    COMPlusThrow(kArgumentOutOfRangeException, W("ArgumentOutOfRange_ArrayLBAndLength"));
-                }
-            }
-
+            if ((length > 0) && (lowerBound + (length - 1) < lowerBound))
+                COMPlusThrow(kArgumentOutOfRangeException, W("ArgumentOutOfRange_ArrayLBAndLength"));
             safeTotalElements = safeTotalElements * S_UINT32(length);
             if (safeTotalElements.IsOverflow())
                 ThrowOutOfMemoryDimensionsExceeded();