[interp] Use correctly-sized writes and reads in Unsafe.AddByteOffset and Unsafe...
authorimhameed <50922266+imhameed@users.noreply.github.com>
Thu, 18 Jul 2019 18:16:46 +0000 (11:16 -0700)
committermonojenkins <jo.shields+jenkins@xamarin.com>
Thu, 18 Jul 2019 18:16:46 +0000 (14:16 -0400)
commit614672ca40ab2e02c657dedf0106ab140d6a0d05
treefd4f168d85b4b57c0bc4e4ddb847f58edb7bb452
parent2c7f6c4a9983e42d3293ab8f7e58a1a42533c36e
[interp] Use correctly-sized writes and reads in Unsafe.AddByteOffset and Unsafe.ByteOffset (mono/mono#15677)

[interp] Use correctly-sized writes and reads in Unsafe.AddByteOffset and Unsafe.ByteOffset

The truncated store to the top of the stack in`MINT_INTRINS_UNSAFE_BYTE_OFFSET` could cause the upper bytes of the address used as the first argument to `ByteOffset` to linger, yielding inaccurate (and usually excessively large) offsets on systems where `sizeof(void *) > sizeof(guint32)`; this made
`System.Text.Unicode.Utf8Utility.GetPointerToFirstInvalidByte` return nonsense results.

The truncation in `MINT_INTRINS_UNSAFE_ADD_BYTE_OFFSET` hasn't, as far as I know, caused any test failures. But `AddByteOffset` takes an `IntPtr` as its second argument, not an `int`.

Fixes mono/mono#14847.

Commit migrated from https://github.com/mono/mono/commit/561b400baa6322dcb3fb6d2b92bd48513fab79f7
src/mono/mono/mini/interp/interp.c