MarshalAs(UnManaged.ByValArray) overflow.
authorTijoy Tom Kalathiparambil <tijoytk@microsoft.com>
Thu, 7 Jul 2016 22:03:01 +0000 (15:03 -0700)
committerTijoy Tom Kalathiparambil <tijoytk@microsoft.com>
Thu, 7 Jul 2016 22:03:01 +0000 (15:03 -0700)
commitf50d625968876e53baaacf879f67f6761113e25c
treec04267da1dc6110c15e21efe87fae16a7afac22a
parentdb9eb2780c50e42f9a4dc49d14c8e865312baa5a
MarshalAs(UnManaged.ByValArray) overflow.
For non-blittable embedded array in structs we ignored the SizeConst and wrote past the
buffer when number of elementsin the arrayis greater than SizeConst.Fix is to truncate
the array at SizeConst
MarshalAs(UnManaged.ByValTStr)
Very subtle case when the SizeConst == Number of bytes required to marshal , we
write the null one past the buffer.This happens only on  machine with non-english
(multi-byte) locale as default. Fix is to check the number of bytes required and
truncate the correctly leaving space for the terminating null.

Commit migrated from https://github.com/dotnet/coreclr/commit/8d51b631b3f582a093a108acfa28c2390fe85f41
14 files changed:
src/coreclr/src/vm/fieldmarshaler.cpp
src/coreclr/src/vm/ilmarshalers.cpp
src/coreclr/src/vm/olevariant.cpp
src/coreclr/src/vm/olevariant.h
src/coreclr/tests/src/Interop/CMakeLists.txt
src/coreclr/tests/src/Interop/MarshalAPI/MarshalStructure/MarshalStructure.cs [new file with mode: 0644]
src/coreclr/tests/src/Interop/MarshalAPI/MarshalStructure/MarshalStructure.csproj [new file with mode: 0644]
src/coreclr/tests/src/Interop/MarshalAPI/MarshalStructure/project.json [new file with mode: 0644]
src/coreclr/tests/src/Interop/SizeConst/CMakeLists.txt [new file with mode: 0644]
src/coreclr/tests/src/Interop/SizeConst/SizeConstNative.cpp [new file with mode: 0644]
src/coreclr/tests/src/Interop/SizeConst/SizeConstTest.cs [new file with mode: 0644]
src/coreclr/tests/src/Interop/SizeConst/SizeConstTest.csproj [new file with mode: 0644]
src/coreclr/tests/src/Interop/SizeConst/project.json [new file with mode: 0644]
src/coreclr/tests/testsUnsupportedOutsideWindows.txt