diff options
author | Miklos Vajna <vmiklos@collabora.com> | 2021-04-23 12:19:49 +0200 |
---|---|---|
committer | Miklos Vajna <vmiklos@collabora.com> | 2021-04-23 14:56:58 +0200 |
commit | 02298dbdfde3432ef757fdc1a28f7e6341254179 (patch) | |
tree | 52406223bbd99996640fdcf2dfa26dd2c3f1665c /embeddedobj | |
parent | 55e2c6c648ed94664903c0c6f53922d03e76b7c1 (diff) |
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@collabora.com>
Tested-by: Jenkins
Diffstat (limited to 'embeddedobj')
-rw-r--r-- | embeddedobj/source/msole/olepersist.cxx | 16 |
1 files changed, 16 insertions, 0 deletions
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!" ); |