xmloff/source/text/XMLChangedRegionImportContext.cxx |   11 ++++++++---
 xmloff/source/text/txtparai.cxx                      |   17 +++++++++++++----
 2 files changed, 21 insertions(+), 7 deletions(-)

New commits:
commit af920245710d1a51d98bba2c18b7002a32865e0b
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Thu Jan 5 18:07:03 2023 +0100
Commit:     Caolán McNamara <caol...@redhat.com>
CommitDate: Fri Jan 6 20:46:30 2023 +0000

    tdf#152710 xmloff: ignore exception in XMLChangedRegionImportContext
    
    The xOldCursor must be restored in all cases.
    
    Also XMLParaContext triggers an exception which ends up aborting the
    import.
    
    Change-Id: I8f4785e0e9bde4c8c484954a4d66f3b82d6ca28c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145094
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>
    (cherry picked from commit e5b5d9c8d33b1dd87e5a50856ad02f21df59dc5b)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145012
    Reviewed-by: Caolán McNamara <caol...@redhat.com>

diff --git a/xmloff/source/text/XMLChangedRegionImportContext.cxx 
b/xmloff/source/text/XMLChangedRegionImportContext.cxx
index 4d43a8de3027..fe00c4a058b9 100644
--- a/xmloff/source/text/XMLChangedRegionImportContext.cxx
+++ b/xmloff/source/text/XMLChangedRegionImportContext.cxx
@@ -122,9 +122,14 @@ void 
XMLChangedRegionImportContext::endFastElement(sal_Int32 )
     {
         // delete last paragraph
         // (one extra paragraph was inserted in the beginning)
-        rtl::Reference<XMLTextImportHelper> rHelper =
-            GetImport().GetTextImport();
-        rHelper->DeleteParagraph();
+        try
+        {
+            GetImport().GetTextImport()->DeleteParagraph();
+        }
+        catch (uno::Exception const&)
+        {   // cursor may be disposed - must reset to old cursor!
+            SAL_INFO("xmloff.text", "XMLChangedRegionImportContext: delete 
paragraph failed");
+        }
 
         GetImport().GetTextImport()->SetCursor(xOldCursor);
         xOldCursor = nullptr;
diff --git a/xmloff/source/text/txtparai.cxx b/xmloff/source/text/txtparai.cxx
index 9844e2628c89..5fffc202612a 100644
--- a/xmloff/source/text/txtparai.cxx
+++ b/xmloff/source/text/txtparai.cxx
@@ -1688,10 +1688,19 @@ void XMLParaContext::endFastElement(sal_Int32 )
 {
     rtl::Reference < XMLTextImportHelper > xTxtImport(
         GetImport().GetTextImport());
-    Reference < XTextRange > xCrsrRange( xTxtImport->GetCursorAsRange() );
-    if( !xCrsrRange.is() )
-        return; // Robust (defective file)
-    Reference < XTextRange > xEnd(xCrsrRange->getStart());
+    Reference<XTextRange> xEnd;
+    try
+    {
+        Reference<XTextRange> const xCrsrRange(xTxtImport->GetCursorAsRange());
+        if (!xCrsrRange.is())
+            return; // Robust (defective file)
+        xEnd = xCrsrRange->getStart();
+    }
+    catch (uno::Exception const&)
+    {
+        SAL_INFO("xmloff.text", "XMLParaContext: cursor disposed?");
+        return;
+    }
 
     // if we have an id set for this paragraph, get a cursor for this
     // paragraph and register it with the given identifier

Reply via email to