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.stahl@allotropia.de>
This commit is contained in:
Michael Stahl 2023-01-05 18:07:03 +01:00
parent 475e59d29b
commit e5b5d9c8d3
2 changed files with 21 additions and 7 deletions

View file

@ -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;

View file

@ -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