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 dotnet/coreclr@16c9dfbae5e5ce18ad0519b31df515820fed2579.

Commit migrated from https://github.com/dotnet/coreclr/commit/835702ea450734c4ce1ac819ccafd99f5a790da8

src/coreclr/src/vm/gchelpers.cpp

index 9b77b0e..bf81847 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();