svtools: fix lost replacement grpahic when updating it via OLE fails
How to reproduce the problem: 1) Create an ODT file which has an OLE object, where the native data i 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) Load the ODT file in hidden mode, e.g. connect to a ./soffice "--accept=socket,host=localhost,port=9999;urp;StarOffice.ServiceManager" process from remote Java, load the file with Hidden=true in the Arguments parameter of loadComponentFromURL(). 4) Save it in a format that reads the replacement graphic of OLE objects, like HTML or DOC. Expected result: the replacement graphic is there. Actual result: the <img> tag has no src attribute (HTML case). The root cause is that in case the document is loaded in hidden mode then the IDataObject::GetData() call in OleComponent::getTransferData() fails, so the OLE objects enters a state where it no longer has its old replacement graphic, but it doesn't have a new one, either. Fix the problem by making this update more transactional in svt::EmbeddedObjectRef::GetReplacement(), so the "document conversion" scenario (load in one format in hidden frame, save in other format) works. Change-Id: I624c372baea56a85fb949bd99046f3af1f258c36 Reviewed-on: https://gerrit.libreoffice.org/62549 Reviewed-by: Miklos Vajna <vmiklos@collabora.co.uk> Tested-by: Jenkins
This commit is contained in:
@@ -399,8 +399,13 @@ bool EmbeddedObjectRef::IsLocked() const
|
||||
|
||||
void EmbeddedObjectRef::GetReplacement( bool bUpdate )
|
||||
{
|
||||
Graphic aOldGraphic;
|
||||
|
||||
if ( bUpdate )
|
||||
{
|
||||
if (mpImpl->pGraphic)
|
||||
aOldGraphic = Graphic(*mpImpl->pGraphic);
|
||||
|
||||
mpImpl->pGraphic.reset();
|
||||
mpImpl->aMediaType.clear();
|
||||
mpImpl->pGraphic.reset( new Graphic );
|
||||
@@ -425,6 +430,13 @@ void EmbeddedObjectRef::GetReplacement( bool bUpdate )
|
||||
rGF.ImportGraphic( *mpImpl->pGraphic, OUString(), *pGraphicStream );
|
||||
mpImpl->mnGraphicVersion++;
|
||||
}
|
||||
|
||||
if (bUpdate && !*mpImpl->pGraphic && aOldGraphic)
|
||||
// We used to have an old graphic, tried to update and the update
|
||||
// failed. Go back to the old graphic instead of having no graphic at
|
||||
// all.
|
||||
(*mpImpl->pGraphic) = aOldGraphic;
|
||||
SAL_WARN("svtools.misc", "EmbeddedObjectRef::GetReplacement: update failed");
|
||||
}
|
||||
|
||||
const Graphic* EmbeddedObjectRef::GetGraphic() const
|
||||
|
||||
Reference in New Issue
Block a user