sw/qa/extras/ooxmlexport/ooxmlexport17.cxx       |    7 ++++++-
 sw/source/core/unocore/unodraw.cxx               |   11 +++++++++++
 sw/source/writerfilter/dmapper/GraphicImport.cxx |   15 +++++++++++----
 3 files changed, 28 insertions(+), 5 deletions(-)

New commits:
commit 428cb59b16325cf86a7036aa923eb0a2088eaa57
Author:     Michael Stahl <[email protected]>
AuthorDate: Tue Nov 4 16:11:56 2025 +0100
Commit:     Caolán McNamara <[email protected]>
CommitDate: Sat Nov 29 15:18:10 2025 +0100

    sw: prevent anchoring SwXShape to its own textbox
    
    SwXShape::setPropertyValue() allows anchoring a shape to its own
    textbox; this actually happens in testTdf146955.
    
    Detect this and throw IllegalArgumentException.
    
    Also catch the exception in GraphicImport::lcl_attribute() so the test
    doesn't fail.
    
    Change-Id: I236e12384e07793e0cf3474fc92657967d9249f0
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193475
    Reviewed-by: Michael Stahl <[email protected]>
    Tested-by: Jenkins
    Signed-off-by: Xisco Fauli <[email protected]>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/193530
    Reviewed-by: Caolán McNamara <[email protected]>

diff --git a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx 
b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
index 1e7e8ce727dc..192d8c6c80c0 100644
--- a/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
+++ b/sw/qa/extras/ooxmlexport/ooxmlexport17.cxx
@@ -976,7 +976,12 @@ DECLARE_OOXMLEXPORT_TEST(testTdf144563, "tdf144563.docx")
 #if !defined(_WIN32)
 CPPUNIT_TEST_FIXTURE(Test, testTdf146955)
 {
-    loadAndReload("tdf146955.odt");
+    auto const url{createFileURL(u"tdf146955.odt")};
+    std::cout << url << ":
";
+    loadFromURL(url, nullptr);
+    save(mpFilter, nullptr);
+    std::cout << maTempFile.GetURL() << ":
";
+    loadFromURL(maTempFile.GetURL(), nullptr);
     // import of a (broken?) DOCX export with dozens of frames raised a SAX 
exception,
     // when the code tried to access to a non-existent footnote
     uno::Reference<text::XFootnotesSupplier> xNotes(mxComponent, 
uno::UNO_QUERY);
diff --git a/sw/source/core/unocore/unodraw.cxx 
b/sw/source/core/unocore/unodraw.cxx
index fa36b2c394ba..ccd823f64f91 100644
--- a/sw/source/core/unocore/unodraw.cxx
+++ b/sw/source/core/unocore/unodraw.cxx
@@ -1135,6 +1135,17 @@ void SwXShape::setPropertyValue(const OUString& 
rPropertyName, const uno::Any& a
                     throw uno::RuntimeException();
                 }
 
+                if (SwStartNode const*const 
pFly{pInternalPam->GetPoint()->GetNode().FindFlyStartNode()})
+                {
+                    if (SwFrameFormat const*const 
pTextBox{SwTextBoxHelper::getOtherTextBoxFormat(pFormat, RES_DRAWFRMFMT)})
+                    {
+                        if (pFly == 
&pTextBox->GetContent().GetContentIdx()->GetNode())
+                        {
+                            throw lang::IllegalArgumentException(u"cannot 
anchor object to itself"_ustr, nullptr, 1);
+                        }
+                    }
+                }
+
                 if (aAnchor.GetAnchorId() == RndStdIds::FLY_AS_CHAR)
                 {
                     //delete old SwFormatFlyCnt
diff --git a/sw/source/writerfilter/dmapper/GraphicImport.cxx 
b/sw/source/writerfilter/dmapper/GraphicImport.cxx
index b26ba56f717e..e7374a4a341f 100644
--- a/sw/source/writerfilter/dmapper/GraphicImport.cxx
+++ b/sw/source/writerfilter/dmapper/GraphicImport.cxx
@@ -971,10 +971,17 @@ void GraphicImport::lcl_attribute(Id nName, const Value& 
rValue)
                         if 
(!xServiceInfo->supportsService(u"com.sun.star.text.TextFrame"_ustr))
                         {
                             bKeepRotation = true;
-                            xShapeProps->setPropertyValue
-                                (getPropertyName(PROP_TEXT_RANGE),
-                                 uno::Any
-                                 
(m_pImpl->m_rDomainMapper.GetCurrentTextRange()));
+                            try
+                            {
+                                xShapeProps->setPropertyValue
+                                    (getPropertyName(PROP_TEXT_RANGE),
+                                     uno::Any
+                                     
(m_pImpl->m_rDomainMapper.GetCurrentTextRange()));
+                            }
+                            catch (lang::IllegalArgumentException const&)
+                            {
+                                SAL_WARN("writerfilter", 
"GraphicImport::lcl_attribute: cannot set anchor");
+                            }
                         }
 
                         awt::Size aSize(m_xShape->getSize());

Reply via email to