Simplify and improve integer overflow checks in Interop (dotnet/coreclr#21732)
authorJan Kotas <jkotas@microsoft.com>
Wed, 2 Jan 2019 13:12:27 +0000 (03:12 -1000)
committerGitHub <noreply@github.com>
Wed, 2 Jan 2019 13:12:27 +0000 (03:12 -1000)
commitb28d87d407aadd14765f91361c8a6ba4b04a588c
tree737b0a4d3a41993c552eabd3793e740898188129
parent139fbfd87b2dcfdd8dea0cc5328bfb58e6dea3b6
Simplify and improve integer overflow checks in Interop (dotnet/coreclr#21732)

- Delete unnecessary CheckStringLength calls for result of string.Length. Managed strings are guaranteed to be under 2GB bytes, so these checks were unnecessary.
- Add `checked(...)` around buffer size computations that may hit potential integer overflow. It does not look like any of these would cause a bug that would lead to buffer overrun, but it is better to catch these early.

Commit migrated from https://github.com/dotnet/coreclr/commit/a5b1c68d4bb8a14042e93acb8f1032db4703b943
src/coreclr/src/System.Private.CoreLib/src/System/Runtime/InteropServices/Marshal.cs
src/coreclr/src/System.Private.CoreLib/src/System/StubHelpers.cs
src/coreclr/src/vm/ilmarshalers.cpp