summaryrefslogtreecommitdiff
path: root/dtrans
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2019-12-31 22:05:59 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2019-12-31 21:01:12 +0100
commit84be3e396cae16a975c7c7f5b892e6b615b73356 (patch)
treebae4db000ef838c434f8986c520f57e9277ec1cc /dtrans
parentf1aec2392dba32e90f2cb0e4ad3c84bcbbd9f305 (diff)
Fix a random crash on paste from clipboard on Windows
Happened to me while debugging Draw; the problem was that for some reason in CDOTransferable::getTransferData clipDataStream was empty at the point of call to byteStreamToAny; thus in byteStreamToOUString, dereferencing negative index happened checking for terminating null, which asserted in Sequence::operator []. I couldn't find the reason of the empty data stream; and I couldn't repro this again, so just add the check to prevent the crash. Change-Id: Id9fde9829828482803f42d6fb106b7f674e5fce7 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/86050 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'dtrans')
-rw-r--r--dtrans/source/win32/dtobj/DOTransferable.cxx6
1 files changed, 5 insertions, 1 deletions
diff --git a/dtrans/source/win32/dtobj/DOTransferable.cxx b/dtrans/source/win32/dtobj/DOTransferable.cxx
index 230a7fbfed8e..afa705abfc56 100644
--- a/dtrans/source/win32/dtobj/DOTransferable.cxx
+++ b/dtrans/source/win32/dtobj/DOTransferable.cxx
@@ -94,7 +94,9 @@ OUString byteStreamToOUString( CDOTransferable::ByteSequence_t& aByteStream )
sal_Int32 nMemSize = aByteStream.getLength( );
// if there is a trailing L"\0" subtract 1 from length
- if ( 0 == aByteStream[ aByteStream.getLength( ) - 2 ] &&
+ // for unknown reason, the sequence may sometimes arrive empty
+ if ( aByteStream.getLength( ) > 1 &&
+ 0 == aByteStream[ aByteStream.getLength( ) - 2 ] &&
0 == aByteStream[ aByteStream.getLength( ) - 1 ] )
nWChars = static_cast< sal_Int32 >( nMemSize / sizeof( sal_Unicode ) ) - 1;
else
@@ -110,6 +112,8 @@ Any byteStreamToAny( CDOTransferable::ByteSequence_t& aByteStream, const Type& a
if ( aRequestedDataType == CPPUTYPE_OUSTRING )
{
OUString str = byteStreamToOUString( aByteStream );
+ if (str.isEmpty())
+ throw RuntimeException();
aAny <<= str;
}
else