[Libreoffice-commits] core.git: dtrans/source

Mike Kaganski (via logerrit) logerrit at kemper.freedesktop.org
Tue Dec 31 20:01:59 UTC 2019


 dtrans/source/win32/dtobj/DOTransferable.cxx |    6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

New commits:
commit 84be3e396cae16a975c7c7f5b892e6b615b73356
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Tue Dec 31 22:05:59 2019 +0300
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Tue Dec 31 21:01:12 2019 +0100

    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 at collabora.com>

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


More information about the Libreoffice-commits mailing list