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

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Fri Apr 23 12:57:37 UTC 2021


 embeddedobj/source/msole/olepersist.cxx |   16 ++++++++++++++++
 1 file changed, 16 insertions(+)

New commits:
commit 02298dbdfde3432ef757fdc1a28f7e6341254179
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Fri Apr 23 12:19:49 2021 +0200
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Fri Apr 23 14:56:58 2021 +0200

    embeddedobj: fix lost native data when updating it via OLE fails, take 2
    
    How to reproduce the problem:
    
    1) Create an ODT file which has an OLE object, where the native data is
    an OLE2 container, containing a Package stream, containing a DOCX file
    
    2) Install some external application on Windows which registers itself
    as a handler for the DOCX CSLID [ this is where writing a testcase for
    this bug is challenging ].
    
    3) Open this document via Java, using URP. Load the document with
    Hidden=true and OnMainThread=true.
    
    4) Save the document using XStorable.store().
    
    Expected result: the native data is there.
    
    Actual result: the native data is sometimes missing (0 bytes).
    
    The root cause is that GetUserClassID() Win32 API call in
    OleComponent::StoreOwnTmpIfNecessary() fails in some cases, and
    re-trying a few times after a small sleep doesn't help.
    
    Handle this error better by doing what
    OleEmbeddedObject::SwitchOwnPersistence(XStorage, OUString) already
    does: discard the old native data only if we have non-empty new native
    data.
    
    A result of the above was that an export to reqif-xhtml (sw HTML export
    with FilterOptions set to xhtmlns=reqif-xhtml) wrote empty \objdata.
    
    Change-Id: I59611601cf09597e9f7727db5bd6d7426fe17b75
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/114537
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>
    Tested-by: Jenkins

diff --git a/embeddedobj/source/msole/olepersist.cxx b/embeddedobj/source/msole/olepersist.cxx
index fddf46d6e658..c4d80bb404fd 100644
--- a/embeddedobj/source/msole/olepersist.cxx
+++ b/embeddedobj/source/msole/olepersist.cxx
@@ -743,6 +743,22 @@ void OleEmbeddedObject::SwitchOwnPersistence( const uno::Reference< embed::XStor
         return;
     }
 
+    uno::Reference<io::XSeekable> xNewSeekable(xNewObjectStream, uno::UNO_QUERY);
+    if (xNewSeekable.is() && xNewSeekable->getLength() == 0)
+    {
+        uno::Reference<io::XSeekable> xOldSeekable(m_xObjectStream, uno::UNO_QUERY);
+        if (xOldSeekable.is() && xOldSeekable->getLength() > 0)
+        {
+            SAL_WARN("embeddedobj.ole", "OleEmbeddedObject::SwitchOwnPersistence(stream version): "
+                                        "empty new stream, reusing old one");
+            uno::Reference<io::XInputStream> xInput = m_xObjectStream->getInputStream();
+            uno::Reference<io::XOutputStream> xOutput = xNewObjectStream->getOutputStream();
+            xOldSeekable->seek(0);
+            comphelper::OStorageHelper::CopyInputToOutput(xInput, xOutput);
+            xNewSeekable->seek(0);
+        }
+    }
+
     try {
         uno::Reference< lang::XComponent > xComponent( m_xObjectStream, uno::UNO_QUERY );
         OSL_ENSURE( !m_xObjectStream.is() || xComponent.is(), "Wrong stream implementation!" );


More information about the Libreoffice-commits mailing list