From e79310d60f417a51c914b065425d1b4b83aa3690 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Thu, 13 Sep 2007 18:42:19 +0000 Subject: [PATCH] don't interpret the first DWORD of data as its size if there is nothing following it (this fixes bug 1791459 for the 2.8 branch) git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/branches/WX_2_8_BRANCH@48663 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- src/msw/ole/dataobj.cpp | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/msw/ole/dataobj.cpp b/src/msw/ole/dataobj.cpp index 4cfcee5e9e..d23ae6fa6b 100644 --- a/src/msw/ole/dataobj.cpp +++ b/src/msw/ole/dataobj.cpp @@ -685,13 +685,14 @@ size_t wxDataObject::GetBufferOffset(const wxDataFormat& format ) return NeedsVerbatimData(format) ? 0 : sizeof(size_t); } -const void* wxDataObject::GetSizeFromBuffer( const void* buffer, size_t* size, - const wxDataFormat& format ) +const void *wxDataObject::GetSizeFromBuffer(const void *buffer, + size_t *size, + const wxDataFormat& format) { // hack: the third parameter is declared non-const in Wine's headers so // cast away the const - size_t realsz = ::HeapSize(::GetProcessHeap(), 0, - wx_const_cast(void*, buffer)); + const size_t realsz = ::HeapSize(::GetProcessHeap(), 0, + wx_const_cast(void*, buffer)); if ( realsz == (size_t)-1 ) { // note that HeapSize() does not set last error @@ -702,9 +703,13 @@ const void* wxDataObject::GetSizeFromBuffer( const void* buffer, size_t* size, *size = realsz; // check if this data has its size prepended (as it was by default for wx - // programs prior 2.6.3): - size_t *p = (size_t *)buffer; - if ( *p == realsz ) + // programs prior 2.6.3): notice that we may still mistakenly interpret the + // start of the real data as size (e.g. suppose the object contains 2 ints + // and the first of them is 8...) but there is no way around it as long as + // we want to keep this compatibility hack (it won't be there any more in + // the next major wx version) + DWORD *p = (DWORD *)buffer; + if ( *p == realsz && realsz > sizeof(DWORD) ) { if ( NeedsVerbatimData(format) ) wxLogDebug(wxT("Apparent data format mismatch: size not needed"));