include/oox/export/shapes.hxx | 2 ++ oox/source/export/shapes.cxx | 36 ++++++++++++++++++++++++++++++++++++ sc/source/filter/xcl97/xcl97rec.cxx | 6 +++--- 3 files changed, 41 insertions(+), 3 deletions(-)
New commits: commit 9bf99c0dcc671e8a7c932d3a27aae28b5e726f1e Author: Justin Luth <[email protected]> AuthorDate: Tue Jan 20 13:51:47 2026 -0500 Commit: Miklos Vajna <[email protected]> CommitDate: Mon Mar 9 15:05:41 2026 +0100 mso-test tdf#73254 xlsx export: invalid xdr:twoCellAnchor The example document fdo73254-1.xls was being reported by MS Excel as corrupt after LO saved it as XLSX. xdr:twoCellAnchor has mandatory subelements so we can't start one unless we have a valid graphic/URL. Fortunately, it is not corrupt to have an empty drawing1.xml containing only a <xdr:wsDr/>. That would have been practically impossible to avoid. Change-Id: Ia0251eb0cee1798cbeb1b8d4f545537ab2485668 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/197699 Reviewed-by: Justin Luth <[email protected]> Tested-by: Jenkins Reviewed-on: https://gerrit.libreoffice.org/c/core/+/197825 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-on: https://gerrit.libreoffice.org/c/core/+/201191 Reviewed-by: Miklos Vajna <[email protected]> diff --git a/include/oox/export/shapes.hxx b/include/oox/export/shapes.hxx index 19bb44118f1a..8bf7487d9e34 100644 --- a/include/oox/export/shapes.hxx +++ b/include/oox/export/shapes.hxx @@ -114,6 +114,8 @@ public: static bool NonEmptyText( const css::uno::Reference< css::uno::XInterface >& xIface ); static bool IsShapeTypeKnown( const css::uno::Reference< css::drawing::XShape >& xShape ); + static bool IsValidShape(const css::uno::Reference<css::drawing::XShape>& xShape, + DocumentType eDocumentType); ShapeExport& WritePolyPolygonShape( const css::uno::Reference< css::drawing::XShape >& xShape, bool bClosed ); diff --git a/oox/source/export/shapes.cxx b/oox/source/export/shapes.cxx index edec05b9315d..100f1097a56a 100644 --- a/oox/source/export/shapes.cxx +++ b/oox/source/export/shapes.cxx @@ -2229,6 +2229,42 @@ bool ShapeExport::IsShapeTypeKnown(const Reference<XShape>& xShape) return constMap.contains(sShapeType); } +bool ShapeExport::IsValidShape(const Reference<XShape>& xShape, DocumentType eDocumentType) +{ + if (!xShape) + return false; + + auto aConverterIterator = constMap.find(xShape->getShapeType()); + if (aConverterIterator == constMap.end()) + return false; + + if (aConverterIterator->second == &ShapeExport::WriteGraphicObjectShape) + { + if (IsNonEmptySimpleText(xShape)) + return true; + + Reference<XPropertySet> xShapeProps(xShape, UNO_QUERY); + Reference<XPropertySetInfo> xShapePropSetInfo + = xShapeProps.is() ? xShapeProps->getPropertySetInfo() : nullptr; + if (!xShapePropSetInfo.is()) + return false; + + uno::Reference<graphic::XGraphic> xGraphic; + xShapeProps->getPropertyValue(u"Graphic"_ustr) >>= xGraphic; + + // tdf#155903 Only for PPTX. Microsoft does not support this feature in Word and Excel. + OUString sMediaURL; + bool bHasMediaURL = eDocumentType == DOCUMENT_PPTX + && xShapePropSetInfo->hasPropertyByName(u"MediaURL"_ustr) + && (xShapeProps->getPropertyValue(u"MediaURL"_ustr) >>= sMediaURL); + + if (!xGraphic.is() && !bHasMediaURL) + return false; + } + + return true; +} + ShapeExport& ShapeExport::WriteShape( const Reference< XShape >& xShape ) { if (!xShape) diff --git a/sc/source/filter/xcl97/xcl97rec.cxx b/sc/source/filter/xcl97/xcl97rec.cxx index fd165830f7f9..47b614133a1b 100644 --- a/sc/source/filter/xcl97/xcl97rec.cxx +++ b/sc/source/filter/xcl97/xcl97rec.cxx @@ -1319,10 +1319,10 @@ bool ScURLTransformer::isExternalURL(const OUString& rURL) const void XclObjAny::SaveXml( XclExpXmlStream& rStrm ) { - // Return early if unknown shape type, otherwise bogus drawing XML gets written - if (!ShapeExport::IsShapeTypeKnown(mxShape)) + // Return early if unknown/invalid shape; otherwise bogus drawing XML gets written + if (!ShapeExport::IsValidShape(mxShape, drawingml::DOCUMENT_XLSX)) { - SAL_INFO("sc.filter", "unknown shape"); + SAL_INFO("sc.filter", "unknown or invalid/incomplete shape"); return; }
