sw/qa/filter/md/data/ole-without-graphic.odt |binary sw/qa/filter/md/md.cxx | 14 ++++++++++++-- sw/source/filter/md/wrtmd.cxx | 15 +++++++++++++-- 3 files changed, 25 insertions(+), 4 deletions(-)
New commits: commit 5ae32bee8dfe5b3264debc02276a3eeac7f51021 Author: Miklos Vajna <[email protected]> AuthorDate: Tue Nov 25 08:30:12 2025 +0100 Commit: Miklos Vajna <[email protected]> CommitDate: Tue Nov 25 17:24:06 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/+/194518 Reviewed-by: Miklos Vajna <[email protected]> Code-Style: Miklos Vajna <[email protected]> Tested-by: Jenkins 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 03e384678bf6..39664c5548a3 100644 --- a/sw/qa/filter/md/md.cxx +++ b/sw/qa/filter/md/md.cxx @@ -71,9 +71,9 @@ CPPUNIT_TEST_FIXTURE(Test, testExportFormula) save(TestFilter::MD); std::string aActual = TempFileToString(); - std::string aExpected("![]()" SAL_NEWLINE_STRING); - CPPUNIT_ASSERT_EQUAL(aExpected, aActual); + CPPUNIT_ASSERT(aActual.starts_with("); + CPPUNIT_ASSERT(aActual.ends_with(")" SAL_NEWLINE_STRING)); } CPPUNIT_TEST_FIXTURE(Test, testExportTableFrame) @@ -979,6 +979,16 @@ CPPUNIT_TEST_FIXTURE(Test, testDocxTemplateMdImport) CPPUNIT_ASSERT_EQUAL(Color(0x156082), pXFillColorItem->GetColorValue()); } +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(TestFilter::MD); +} + 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 c1d5175537a4..a2485d863cff 100644 --- a/sw/source/filter/md/wrtmd.cxx +++ b/sw/source/filter/md/wrtmd.cxx @@ -185,9 +185,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();
