Huw Davies : ole32: Properly align HMETAFILEPICT marshal data.
Alexandre Julliard
julliard at winehq.org
Fri Dec 8 13:51:30 CST 2017
Module: wine
Branch: master
Commit: 718fb9deb37b3c63078c039395b2a55721d90a07
URL: http://source.winehq.org/git/wine.git/?a=commit;h=718fb9deb37b3c63078c039395b2a55721d90a07
Author: Huw Davies <huw at codeweavers.com>
Date: Fri Dec 8 10:26:51 2017 +0000
ole32: Properly align HMETAFILEPICT marshal data.
Signed-off-by: Huw Davies <huw at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/ole32/tests/usrmarshal.c | 26 ++++++++++++++------------
dlls/ole32/usrmarshal.c | 10 +++++++---
2 files changed, 21 insertions(+), 15 deletions(-)
diff --git a/dlls/ole32/tests/usrmarshal.c b/dlls/ole32/tests/usrmarshal.c
index 7ab23ad..3919395 100644
--- a/dlls/ole32/tests/usrmarshal.c
+++ b/dlls/ole32/tests/usrmarshal.c
@@ -502,12 +502,12 @@ static void test_marshal_HMETAFILEPICT(void)
GlobalUnlock(hmfp);
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, NULL, 0, MSHCTX_DIFFERENTMACHINE);
- size = HMETAFILEPICT_UserSize(&umcb.Flags, 0, &hmfp);
- ok(size > 20, "size should be at least 20 bytes, not %d\n", size);
+ size = HMETAFILEPICT_UserSize(&umcb.Flags, 1, &hmfp);
+ ok(size > 24, "size should be at least 24 bytes, not %d\n", size);
buffer = HeapAlloc(GetProcessHeap(), 0, size);
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_DIFFERENTMACHINE);
- buffer_end = HMETAFILEPICT_UserMarshal(&umcb.Flags, buffer, &hmfp);
- wirehmfp = buffer;
+ buffer_end = HMETAFILEPICT_UserMarshal(&umcb.Flags, buffer + 1, &hmfp);
+ wirehmfp = buffer + 4;
ok(*(DWORD *)wirehmfp == WDT_REMOTE_CALL, "wirestgm + 0x0 should be WDT_REMOTE_CALL instead of 0x%08x\n", *(DWORD *)wirehmfp);
wirehmfp += sizeof(DWORD);
ok(*(DWORD *)wirehmfp == (DWORD)(DWORD_PTR)hmfp, "wirestgm + 0x4 should be hmf instead of 0x%08x\n", *(DWORD *)wirehmfp);
@@ -528,16 +528,16 @@ static void test_marshal_HMETAFILEPICT(void)
wirehmfp += sizeof(DWORD);
/* Note use (buffer_end - buffer) instead of size here, because size is an
* overestimate with native */
- ok(*(DWORD *)wirehmfp == (buffer_end - buffer - 0x28), "wirestgm + 0x20 should be size - 0x34 instead of 0x%08x\n", *(DWORD *)wirehmfp);
+ ok(*(DWORD *)wirehmfp == (buffer_end - buffer - 0x2c), "wirestgm + 0x20 should be size - 0x34 instead of 0x%08x\n", *(DWORD *)wirehmfp);
wirehmfp += sizeof(DWORD);
- ok(*(DWORD *)wirehmfp == (buffer_end - buffer - 0x28), "wirestgm + 0x24 should be size - 0x34 instead of 0x%08x\n", *(DWORD *)wirehmfp);
+ ok(*(DWORD *)wirehmfp == (buffer_end - buffer - 0x2c), "wirestgm + 0x24 should be size - 0x34 instead of 0x%08x\n", *(DWORD *)wirehmfp);
wirehmfp += sizeof(DWORD);
ok(*(WORD *)wirehmfp == 1, "wirehmfp + 0x28 should be 1 instead of 0x%08x\n", *(DWORD *)wirehmfp);
/* ... rest of data not tested - refer to tests for GetMetaFileBits
* at this point */
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_DIFFERENTMACHINE);
- HMETAFILEPICT_UserUnmarshal(&umcb.Flags, buffer, &hmfp2);
+ HMETAFILEPICT_UserUnmarshal(&umcb.Flags, buffer + 1, &hmfp2);
ok(hmfp2 != NULL, "HMETAFILEPICT didn't unmarshal\n");
HeapFree(GetProcessHeap(), 0, buffer);
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, NULL, 0, MSHCTX_DIFFERENTMACHINE);
@@ -551,12 +551,13 @@ static void test_marshal_HMETAFILEPICT(void)
hmfp = NULL;
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, NULL, 0, MSHCTX_DIFFERENTMACHINE);
- size = HMETAFILEPICT_UserSize(&umcb.Flags, 0, &hmfp);
- ok(size == 8, "size should be 8 bytes, not %d\n", size);
+ size = HMETAFILEPICT_UserSize(&umcb.Flags, 1, &hmfp);
+ ok(size == 12, "size should be 12 bytes, not %d\n", size);
buffer = HeapAlloc(GetProcessHeap(), 0, size);
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_DIFFERENTMACHINE);
- HMETAFILEPICT_UserMarshal(&umcb.Flags, buffer, &hmfp);
- wirehmfp = buffer;
+ buffer_end = HMETAFILEPICT_UserMarshal(&umcb.Flags, buffer + 1, &hmfp);
+ ok(buffer_end == buffer + size, "got %p buffer %p\n", buffer_end, buffer);
+ wirehmfp = buffer + 4;
ok(*(DWORD *)wirehmfp == WDT_REMOTE_CALL, "wirestgm + 0x0 should be WDT_REMOTE_CALL instead of 0x%08x\n", *(DWORD *)wirehmfp);
wirehmfp += sizeof(DWORD);
ok(*(DWORD *)wirehmfp == (DWORD)(DWORD_PTR)hmfp, "wirestgm + 0x4 should be hmf instead of 0x%08x\n", *(DWORD *)wirehmfp);
@@ -564,7 +565,8 @@ static void test_marshal_HMETAFILEPICT(void)
hmfp2 = NULL;
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, buffer, size, MSHCTX_DIFFERENTMACHINE);
- HMETAFILEPICT_UserUnmarshal(&umcb.Flags, buffer, &hmfp2);
+ buffer_end = HMETAFILEPICT_UserUnmarshal(&umcb.Flags, buffer + 1, &hmfp2);
+ ok(buffer_end == buffer + size, "got %p buffer %p\n", buffer_end, buffer);
ok(hmfp2 == NULL, "NULL HMETAFILE didn't unmarshal\n");
HeapFree(GetProcessHeap(), 0, buffer);
init_user_marshal_cb(&umcb, &stub_msg, &rpc_msg, NULL, 0, MSHCTX_DIFFERENTMACHINE);
diff --git a/dlls/ole32/usrmarshal.c b/dlls/ole32/usrmarshal.c
index d773684..63eead1 100644
--- a/dlls/ole32/usrmarshal.c
+++ b/dlls/ole32/usrmarshal.c
@@ -1291,11 +1291,11 @@ void __RPC_USER HENHMETAFILE_UserFree(ULONG *pFlags, HENHMETAFILE *phEmf)
* the first parameter is a ULONG.
* This function is only intended to be called by the RPC runtime.
*/
-ULONG __RPC_USER HMETAFILEPICT_UserSize(ULONG *pFlags, ULONG StartingSize, HMETAFILEPICT *phMfp)
+ULONG __RPC_USER HMETAFILEPICT_UserSize(ULONG *pFlags, ULONG size, HMETAFILEPICT *phMfp)
{
- ULONG size = StartingSize;
+ TRACE("(%s, %d, &%p)\n", debugstr_user_flags(pFlags), size, *phMfp);
- TRACE("(%s, %d, &%p)\n", debugstr_user_flags(pFlags), StartingSize, *phMfp);
+ ALIGN_LENGTH(size, 3);
size += sizeof(ULONG);
@@ -1345,6 +1345,8 @@ unsigned char * __RPC_USER HMETAFILEPICT_UserMarshal(ULONG *pFlags, unsigned cha
{
TRACE("(%s, %p, &%p)\n", debugstr_user_flags(pFlags), pBuffer, *phMfp);
+ ALIGN_POINTER(pBuffer, 3);
+
if (LOWORD(*pFlags) == MSHCTX_INPROC)
{
if (sizeof(HMETAFILEPICT) == 8)
@@ -1408,6 +1410,8 @@ unsigned char * __RPC_USER HMETAFILEPICT_UserUnmarshal(ULONG *pFlags, unsigned c
TRACE("(%s, %p, %p)\n", debugstr_user_flags(pFlags), pBuffer, phMfp);
+ ALIGN_POINTER(pBuffer, 3);
+
fContext = *(ULONG *)pBuffer;
pBuffer += sizeof(ULONG);
More information about the wine-cvs
mailing list