[Libreoffice-commits] core.git: writerfilter/source

Miklos Vajna (via logerrit) logerrit at kemper.freedesktop.org
Tue Mar 31 07:06:42 UTC 2020


 writerfilter/source/filter/RtfFilter.cxx    |   14 ++++++++------
 writerfilter/source/filter/WriterFilter.cxx |    5 ++++-
 2 files changed, 12 insertions(+), 7 deletions(-)

New commits:
commit c0f4bdcc7ca45e2920c676e5734353ba598bcdbc
Author:     Miklos Vajna <vmiklos at collabora.com>
AuthorDate: Mon Mar 30 21:10:33 2020 +0200
Commit:     Miklos Vajna <vmiklos at collabora.com>
CommitDate: Tue Mar 31 09:05:58 2020 +0200

    RTF import: reset writerfilter bit even if the import fails
    
    The old code did not handle when e.g. a
    lang::WrappedTargetRuntimeException is thrown between the set and unset.
    
    The DOCX import had the same problem.
    
    Change-Id: I7336d08057a875db985e8b647b320abd97c6eb81
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/91381
    Tested-by: Jenkins
    Reviewed-by: Miklos Vajna <vmiklos at collabora.com>

diff --git a/writerfilter/source/filter/RtfFilter.cxx b/writerfilter/source/filter/RtfFilter.cxx
index cf1b31aeb016..bfa9a208786e 100644
--- a/writerfilter/source/filter/RtfFilter.cxx
+++ b/writerfilter/source/filter/RtfFilter.cxx
@@ -35,6 +35,7 @@
 #include <unotools/mediadescriptor.hxx>
 #include <unotools/streamwrap.hxx>
 #include <unotools/ucbstreamhelper.hxx>
+#include <comphelper/scopeguard.hxx>
 
 #include <dmapper/DomainMapperFactory.hxx>
 #include <rtftok/RTFDocument.hxx>
@@ -102,6 +103,13 @@ sal_Bool RtfFilter::filter(const uno::Sequence<beans::PropertyValue>& rDescripto
         xDocProps.set(m_xDstDoc, uno::UNO_QUERY);
         xDocProps->setPropertyValue("UndocumentedWriterfilterHack", uno::makeAny(true));
     }
+    comphelper::ScopeGuard g([xDocProps] {
+        if (xDocProps.is()) // not in cppunittest?
+        {
+            // note: pStream.clear calls RemoveLastParagraph()
+            xDocProps->setPropertyValue("UndocumentedWriterfilterHack", uno::makeAny(false));
+        }
+    });
 
     try
     {
@@ -166,12 +174,6 @@ sal_Bool RtfFilter::filter(const uno::Sequence<beans::PropertyValue>& rDescripto
         TOOLS_INFO_EXCEPTION("writerfilter", "Exception caught");
     }
 
-    if (m_xDstDoc.is()) // not in cppunittest?
-    {
-        // note: pStream.clear calls RemoveLastParagraph()
-        xDocProps->setPropertyValue("UndocumentedWriterfilterHack", uno::makeAny(false));
-    }
-
     if (xStatusIndicator.is())
         xStatusIndicator->end();
     return bResult;
diff --git a/writerfilter/source/filter/WriterFilter.cxx b/writerfilter/source/filter/WriterFilter.cxx
index a043dcb2764a..5e14545b9e11 100644
--- a/writerfilter/source/filter/WriterFilter.cxx
+++ b/writerfilter/source/filter/WriterFilter.cxx
@@ -44,6 +44,7 @@
 #include <rtl/ref.hxx>
 #include <sal/log.hxx>
 #include <tools/diagnose_ex.h>
+#include <comphelper/scopeguard.hxx>
 
 using namespace ::com::sun::star;
 
@@ -157,6 +158,9 @@ sal_Bool WriterFilter::filter(const uno::Sequence<beans::PropertyValue>& rDescri
     {
         uno::Reference<beans::XPropertySet> const xDocProps(m_xDstDoc, uno::UNO_QUERY);
         xDocProps->setPropertyValue("UndocumentedWriterfilterHack", uno::makeAny(true));
+        comphelper::ScopeGuard g([xDocProps] {
+            xDocProps->setPropertyValue("UndocumentedWriterfilterHack", uno::makeAny(false));
+        });
         utl::MediaDescriptor aMediaDesc(rDescriptor);
         bool bRepairStorage = aMediaDesc.getUnpackedValueOrDefault("RepairPackage", false);
         bool bSkipImages
@@ -283,7 +287,6 @@ sal_Bool WriterFilter::filter(const uno::Sequence<beans::PropertyValue>& rDescri
         pStream.clear();
 
         // note: pStream.clear calls RemoveLastParagraph()
-        xDocProps->setPropertyValue("UndocumentedWriterfilterHack", uno::makeAny(false));
 
         return true;
     }


More information about the Libreoffice-commits mailing list