sw/qa/filter/md/data/ole-without-graphic.odt |binary sw/qa/filter/md/md.cxx | 10 ++++++++++ sw/source/filter/md/wrtmd.cxx | 15 +++++++++++++-- 3 files changed, 23 insertions(+), 2 deletions(-)
New commits: commit 38189fddf73c4ceed6385951b40279dc889580ce Author: Miklos Vajna <[email protected]> AuthorDate: Tue Nov 25 08:30:12 2025 +0100 Commit: Caolán McNamara <[email protected]> CommitDate: Tue Nov 25 12:34:09 2025 +0100 Related: tdf#169251 sw markdown export: fix crash on OLE with no graphic It turns out Writer can have broken OLE objects without a replacement graphic, so replace the assert with error handling. While at it, also implement export of the OLE graphics when it's there. (Insert a math object with a simple "a = b / c" formula to trigger that codepath.) Change-Id: Iad502bf243adacfce4d1bc903a77f19e4b81b007 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/194506 Reviewed-by: Andras Timar <[email protected]> Tested-by: Jenkins CollaboraOffice <[email protected]> Code-Style: Miklos Vajna <[email protected]> (cherry picked from commit 6b419bf6ca4e9e05b024b0aa4a3416860764706f) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/194519 Tested-by: Miklos Vajna <[email protected]> Reviewed-by: Caolán McNamara <[email protected]> diff --git a/sw/qa/filter/md/data/ole-without-graphic.odt b/sw/qa/filter/md/data/ole-without-graphic.odt new file mode 100644 index 000000000000..7bb5fcb09531 Binary files /dev/null and b/sw/qa/filter/md/data/ole-without-graphic.odt differ diff --git a/sw/qa/filter/md/md.cxx b/sw/qa/filter/md/md.cxx index a970a270cae4..1da8b18536b0 100644 --- a/sw/qa/filter/md/md.cxx +++ b/sw/qa/filter/md/md.cxx @@ -912,6 +912,16 @@ CPPUNIT_TEST_FIXTURE(Test, testEmbeddedAnchoredImageMdExport) CPPUNIT_ASSERT(aActual.ends_with(") B" SAL_NEWLINE_STRING)); } +CPPUNIT_TEST_FIXTURE(Test, testOLEWithoutGraphicMdExport) +{ + // Given a document with an OLE object that has no graphic: + createSwDoc("ole-without-graphic.odt"); + + // When exporting it as markdown: + // Then make sure this doesn't crash: + save(mpFilter); +} + CPPUNIT_PLUGIN_IMPLEMENT(); /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sw/source/filter/md/wrtmd.cxx b/sw/source/filter/md/wrtmd.cxx index df423ad6a334..4ff8d638b41f 100644 --- a/sw/source/filter/md/wrtmd.cxx +++ b/sw/source/filter/md/wrtmd.cxx @@ -175,9 +175,20 @@ void ApplyFlyFrameFormat(const SwFlyFrameFormat& rFrameFormat, SwMDWriter& rWrt, else if (eNodeType == SwNodeType::Ole) { SwOLENode* pOLENode = rWrt.m_pDoc->GetNodes()[nStart]->GetOLENode(); - assert(pOLENode->GetGraphic()); + if (!pOLENode->GetGraphic()) + { + return; + } + + // Assume that the graphic of OLE objects is never linked. aGraphic = *pOLENode->GetGraphic(); - // TODO fill aGraphicURL with the right info + OUString aGraphicInBase64; + if (!XOutBitmap::GraphicToBase64(aGraphic, aGraphicInBase64)) + { + return; + } + + aGraphicURL = "data:" + aGraphicInBase64; } const OUString& rBaseURL = rWrt.GetBaseURL();
