From 84be3e396cae16a975c7c7f5b892e6b615b73356 Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Tue, 31 Dec 2019 22:05:59 +0300 Subject: 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 --- dtrans/source/win32/dtobj/DOTransferable.cxx | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 -- cgit