[Libreoffice-commits] core.git: filter/source include/comphelper include/sfx2 offapi/com offapi/UnoApi_offapi.mk officecfg/registry sfx2/Library_sfx.mk sfx2/source uui/inc uui/source

Michael Meeks michael.meeks at collabora.com
Fri Mar 16 20:34:20 UTC 2018


 filter/source/config/cache/constant.hxx                            |    1 
 filter/source/config/cache/filtercache.cxx                         |    6 +
 filter/source/config/fragments/filters/AbiWord.xcu                 |    2 
 filter/source/config/fragments/filters/MWAW_Bitmap.xcu             |    2 
 filter/source/config/fragments/filters/MWAW_Database.xcu           |    2 
 filter/source/config/fragments/filters/MWAW_Drawing.xcu            |    2 
 filter/source/config/fragments/filters/MWAW_Presentation.xcu       |    2 
 filter/source/config/fragments/filters/MWAW_Spreadsheet.xcu        |    2 
 filter/source/config/fragments/filters/MWAW_Text_Document.xcu      |    2 
 filter/source/config/fragments/filters/StarOffice_XML__Base_.xcu   |    2 
 filter/source/config/fragments/filters/StarOffice_XML__Writer_.xcu |    2 
 filter/source/config/fragments/filters/T602Document.xcu            |    2 
 filter/source/config/fragments/filters/XPM.xcu                     |    2 
 filter/source/config/fragments/filters/writer_MIZI_Hwp_97.xcu      |    2 
 include/comphelper/documentconstants.hxx                           |    4 
 include/sfx2/docfilt.hxx                                           |    3 
 include/sfx2/objsh.hxx                                             |    3 
 offapi/UnoApi_offapi.mk                                            |    1 
 offapi/com/sun/star/document/ExoticFileLoadException.idl           |   34 ++++++++
 officecfg/registry/schema/org/openoffice/Office/Common.xcs         |   23 +++++
 sfx2/Library_sfx.mk                                                |    1 
 sfx2/source/doc/exoticfileloadexception.cxx                        |   42 ++++++++++
 sfx2/source/doc/exoticfileloadexception.hxx                        |   42 ++++++++++
 sfx2/source/doc/objstor.cxx                                        |   37 ++++++++
 uui/inc/ids.hrc                                                    |    2 
 uui/inc/ids.hxx                                                    |    1 
 uui/source/iahndl.cxx                                              |   25 +++++
 27 files changed, 235 insertions(+), 14 deletions(-)

New commits:
commit 25e4b59b2e9805ebd3c38c40e5591125a05ed5b0
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Wed Feb 25 15:07:19 2015 +0000

    First cut at annotating 'exotic' filters.
    
    The idea being that we can improve security by warning for these.
    
    Change-Id: I7d993417bfb6a8fe868bc3e07ccbcfe71bf285ff
    Reviewed-on: https://gerrit.libreoffice.org/50387
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Andras Timar <andras.timar at collabora.com>

diff --git a/filter/source/config/cache/constant.hxx b/filter/source/config/cache/constant.hxx
index c8a45889ee0e..2a5da1529de3 100644
--- a/filter/source/config/cache/constant.hxx
+++ b/filter/source/config/cache/constant.hxx
@@ -121,6 +121,7 @@
 #define  FLAGNAME_TEMPLATEPATH      "TEMPLATEPATH"
 #define  FLAGNAME_COMBINED          "COMBINED"
 #define FLAGNAME_SUPPORTSSIGNING "SUPPORTSSIGNING"
+#define FLAGNAME_EXOTIC "EXOTIC"
 
 /** @short  some uno service names.
  */
diff --git a/filter/source/config/cache/filtercache.cxx b/filter/source/config/cache/filtercache.cxx
index f6d80f97540c..bb3bfdc7b9d1 100644
--- a/filter/source/config/cache/filtercache.cxx
+++ b/filter/source/config/cache/filtercache.cxx
@@ -1843,6 +1843,7 @@ css::uno::Sequence< OUString > FilterCache::impl_convertFlagField2FlagNames(SfxF
     if (nFlags & SfxFilterFlags::COMBINED         ) lFlagNames.emplace_back(FLAGNAME_COMBINED         );
     if (nFlags & SfxFilterFlags::SUPPORTSSIGNING) lFlagNames.emplace_back(FLAGNAME_SUPPORTSSIGNING);
     if (nFlags & SfxFilterFlags::GPGENCRYPTION) lFlagNames.emplace_back(FLAGNAME_GPGENCRYPTION);
+    if (nFlags & SfxFilterFlags::EXOTIC) lFlagNames.emplace_back(FLAGNAME_EXOTIC);
 
     return comphelper::containerToSequence(lFlagNames);
 }
@@ -1883,6 +1884,11 @@ SfxFilterFlags FilterCache::impl_convertFlagNames2FlagField(const css::uno::Sequ
             nField |= SfxFilterFlags::ENCRYPTION;
             continue;
         }
+        if (pNames[i] == FLAGNAME_EXOTIC)
+        {
+            nField |= SfxFilterFlags::EXOTIC;
+            continue;
+        }
         if (pNames[i] == FLAGNAME_EXPORT)
         {
             nField |= SfxFilterFlags::EXPORT;
diff --git a/filter/source/config/fragments/filters/AbiWord.xcu b/filter/source/config/fragments/filters/AbiWord.xcu
index 115febd8aafe..a309ac87d379 100644
--- a/filter/source/config/fragments/filters/AbiWord.xcu
+++ b/filter/source/config/fragments/filters/AbiWord.xcu
@@ -16,7 +16,7 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 -->
     <node oor:name="AbiWord" oor:op="replace">
-        <prop oor:name="Flags"><value>IMPORT ALIEN 3RDPARTYFILTER</value></prop>
+        <prop oor:name="Flags"><value>IMPORT ALIEN 3RDPARTYFILTER EXOTIC</value></prop>
         <prop oor:name="UIComponent"/>
         <prop oor:name="FilterService"><value>com.sun.star.comp.Writer.AbiWordImportFilter</value></prop>
         <prop oor:name="UserData"><value>ABW</value></prop>
diff --git a/filter/source/config/fragments/filters/MWAW_Bitmap.xcu b/filter/source/config/fragments/filters/MWAW_Bitmap.xcu
index 034b72132219..3e70cc62f972 100644
--- a/filter/source/config/fragments/filters/MWAW_Bitmap.xcu
+++ b/filter/source/config/fragments/filters/MWAW_Bitmap.xcu
@@ -9,7 +9,7 @@
 
 <node oor:name="MWAW_Bitmap" oor:op="replace">
     <prop oor:name="Flags">
-        <value>IMPORT ALIEN 3RDPARTYFILTER PREFERRED</value>
+        <value>IMPORT ALIEN 3RDPARTYFILTER PREFERRED EXOTIC</value>
     </prop>
     <prop oor:name="FilterService">
         <value>com.sun.star.comp.Draw.MWAWDrawImportFilter</value>
diff --git a/filter/source/config/fragments/filters/MWAW_Database.xcu b/filter/source/config/fragments/filters/MWAW_Database.xcu
index 3ff4182ef6c6..075f3ed9e13e 100644
--- a/filter/source/config/fragments/filters/MWAW_Database.xcu
+++ b/filter/source/config/fragments/filters/MWAW_Database.xcu
@@ -9,7 +9,7 @@
 
 <node oor:name="MWAW_Database" oor:op="replace">
     <prop oor:name="Flags">
-        <value>IMPORT ALIEN 3RDPARTYFILTER PREFERRED</value>
+        <value>IMPORT ALIEN 3RDPARTYFILTER PREFERRED EXOTIC</value>
     </prop>
     <prop oor:name="FilterService">
         <value>com.sun.star.comp.Calc.MWAWCalcImportFilter</value>
diff --git a/filter/source/config/fragments/filters/MWAW_Drawing.xcu b/filter/source/config/fragments/filters/MWAW_Drawing.xcu
index b92f378497dd..1b9ec56d27ee 100644
--- a/filter/source/config/fragments/filters/MWAW_Drawing.xcu
+++ b/filter/source/config/fragments/filters/MWAW_Drawing.xcu
@@ -9,7 +9,7 @@
 
 <node oor:name="MWAW_Drawing" oor:op="replace">
     <prop oor:name="Flags">
-        <value>IMPORT ALIEN 3RDPARTYFILTER PREFERRED</value>
+        <value>IMPORT ALIEN 3RDPARTYFILTER PREFERRED EXOTIC</value>
     </prop>
     <prop oor:name="FilterService">
         <value>com.sun.star.comp.Draw.MWAWDrawImportFilter</value>
diff --git a/filter/source/config/fragments/filters/MWAW_Presentation.xcu b/filter/source/config/fragments/filters/MWAW_Presentation.xcu
index 8cfa9445621d..aae6598b27c0 100644
--- a/filter/source/config/fragments/filters/MWAW_Presentation.xcu
+++ b/filter/source/config/fragments/filters/MWAW_Presentation.xcu
@@ -9,7 +9,7 @@
 
 <node oor:name="MWAW_Presentation" oor:op="replace">
     <prop oor:name="Flags">
-        <value>IMPORT ALIEN 3RDPARTYFILTER PREFERRED</value>
+        <value>IMPORT ALIEN 3RDPARTYFILTER PREFERRED EXOTIC</value>
     </prop>
     <prop oor:name="FilterService">
         <value>com.sun.star.comp.Impress.MWAWPresentationImportFilter</value>
diff --git a/filter/source/config/fragments/filters/MWAW_Spreadsheet.xcu b/filter/source/config/fragments/filters/MWAW_Spreadsheet.xcu
index db388c55fe44..5461b7fe20ba 100644
--- a/filter/source/config/fragments/filters/MWAW_Spreadsheet.xcu
+++ b/filter/source/config/fragments/filters/MWAW_Spreadsheet.xcu
@@ -9,7 +9,7 @@
 
 <node oor:name="MWAW_Spreadsheet" oor:op="replace">
     <prop oor:name="Flags">
-        <value>IMPORT ALIEN 3RDPARTYFILTER PREFERRED</value>
+        <value>IMPORT ALIEN 3RDPARTYFILTER PREFERRED EXOTIC</value>
     </prop>
     <prop oor:name="FilterService">
         <value>com.sun.star.comp.Calc.MWAWCalcImportFilter</value>
diff --git a/filter/source/config/fragments/filters/MWAW_Text_Document.xcu b/filter/source/config/fragments/filters/MWAW_Text_Document.xcu
index f030fb71b198..cfbd5556f29a 100644
--- a/filter/source/config/fragments/filters/MWAW_Text_Document.xcu
+++ b/filter/source/config/fragments/filters/MWAW_Text_Document.xcu
@@ -9,7 +9,7 @@
 
 <node oor:name="MWAW_Text_Document" oor:op="replace">
     <prop oor:name="Flags">
-        <value>IMPORT ALIEN 3RDPARTYFILTER PREFERRED</value>
+        <value>IMPORT ALIEN 3RDPARTYFILTER PREFERRED EXOTIC</value>
     </prop>
     <prop oor:name="FilterService">
         <value>com.sun.star.comp.Writer.MWAWImportFilter</value>
diff --git a/filter/source/config/fragments/filters/StarOffice_XML__Base_.xcu b/filter/source/config/fragments/filters/StarOffice_XML__Base_.xcu
index 4c33a806fd9d..344843043b7c 100644
--- a/filter/source/config/fragments/filters/StarOffice_XML__Base_.xcu
+++ b/filter/source/config/fragments/filters/StarOffice_XML__Base_.xcu
@@ -16,7 +16,7 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 -->
     <node oor:name="StarOffice XML (Base)" oor:op="replace">
-        <prop oor:name="Flags"><value>IMPORT OWN DEFAULT 3RDPARTYFILTER ENCRYPTION</value></prop>
+        <prop oor:name="Flags"><value>IMPORT OWN DEFAULT 3RDPARTYFILTER ENCRYPTION EXOTIC</value></prop>
         <prop oor:name="UIComponent"/>
         <prop oor:name="FilterService"/>
         <prop oor:name="UserData"/>
diff --git a/filter/source/config/fragments/filters/StarOffice_XML__Writer_.xcu b/filter/source/config/fragments/filters/StarOffice_XML__Writer_.xcu
index ee3638bc0cc8..ba7db694d6ca 100644
--- a/filter/source/config/fragments/filters/StarOffice_XML__Writer_.xcu
+++ b/filter/source/config/fragments/filters/StarOffice_XML__Writer_.xcu
@@ -16,7 +16,7 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 -->
     <node oor:name="StarOffice XML (Writer)" oor:op="replace">
-        <prop oor:name="Flags"><value>IMPORT TEMPLATE OWN ALIEN PREFERRED ENCRYPTION</value></prop>
+        <prop oor:name="Flags"><value>IMPORT TEMPLATE OWN ALIEN PREFERRED ENCRYPTION EXOTIC</value></prop>
         <prop oor:name="UIComponent"/>
         <prop oor:name="FilterService"/>
         <prop oor:name="UserData"><value>CXML</value></prop>
diff --git a/filter/source/config/fragments/filters/T602Document.xcu b/filter/source/config/fragments/filters/T602Document.xcu
index 436d7c8ea2b6..bf8a68fa691a 100644
--- a/filter/source/config/fragments/filters/T602Document.xcu
+++ b/filter/source/config/fragments/filters/T602Document.xcu
@@ -16,7 +16,7 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 -->
     <node oor:name="T602Document" oor:op="replace">
-        <prop oor:name="Flags"><value>IMPORT ALIEN 3RDPARTYFILTER PREFERRED</value></prop>
+        <prop oor:name="Flags"><value>IMPORT ALIEN 3RDPARTYFILTER PREFERRED EXOTIC</value></prop>
         <prop oor:name="UIComponent"/>
         <prop oor:name="FilterService"><value>com.sun.star.comp.Writer.T602ImportFilter</value></prop>
         <prop oor:name="UserData"><value>602</value></prop>
diff --git a/filter/source/config/fragments/filters/XPM.xcu b/filter/source/config/fragments/filters/XPM.xcu
index 83c1e32c599b..8a67b710f1a2 100644
--- a/filter/source/config/fragments/filters/XPM.xcu
+++ b/filter/source/config/fragments/filters/XPM.xcu
@@ -16,7 +16,7 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 -->
     <node oor:name="XPM" oor:op="replace">
-        <prop oor:name="Flags"><value>IMPORT ALIEN</value></prop>
+        <prop oor:name="Flags"><value>IMPORT ALIEN EXOTIC</value></prop>
         <prop oor:name="UIComponent"/>
         <prop oor:name="FilterService"/>
         <prop oor:name="UserData"><value></value></prop>
diff --git a/filter/source/config/fragments/filters/writer_MIZI_Hwp_97.xcu b/filter/source/config/fragments/filters/writer_MIZI_Hwp_97.xcu
index 1eba0ffbbd3c..2b717c8cb944 100644
--- a/filter/source/config/fragments/filters/writer_MIZI_Hwp_97.xcu
+++ b/filter/source/config/fragments/filters/writer_MIZI_Hwp_97.xcu
@@ -16,7 +16,7 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 -->
     <node oor:name="writer_MIZI_Hwp_97" oor:op="replace">
-        <prop oor:name="Flags"><value>IMPORT ALIEN 3RDPARTYFILTER</value></prop>
+        <prop oor:name="Flags"><value>IMPORT ALIEN 3RDPARTYFILTER EXOTIC</value></prop>
         <prop oor:name="UIComponent"/>
         <prop oor:name="FilterService"><value>com.sun.comp.hwpimport.HwpImportFilter</value></prop>
         <prop oor:name="UserData"><value></value></prop>
diff --git a/include/comphelper/documentconstants.hxx b/include/comphelper/documentconstants.hxx
index 9447a7b17fc6..89d5178d33d5 100644
--- a/include/comphelper/documentconstants.hxx
+++ b/include/comphelper/documentconstants.hxx
@@ -83,6 +83,7 @@
 // Preferred               - preferred filter for a particular type
 // 3rdPartyFilter          - implemented as a UNO component
 // Default                 - default filter for this document type
+// Exotic                  - an unusual/legacy file-format, we don't normally see
 //
 // (The 3rdPartyFilter flag is here called StarONE)
 //
@@ -106,6 +107,7 @@ enum class SfxFilterFlags
     CONSULTSERVICE    = 0x00040000L,
     STARONEFILTER     = 0x00080000L,
     PACKED            = 0x00100000L,
+    EXOTIC            = 0x00200000L,
     COMBINED          = 0x00800000L,
 
     ENCRYPTION        = 0x01000000L,
@@ -118,7 +120,7 @@ enum class SfxFilterFlags
 
 namespace o3tl
 {
-    template<> struct typed_flags<SfxFilterFlags> : is_typed_flags<SfxFilterFlags, 0x779f157fL> {};
+    template<> struct typed_flags<SfxFilterFlags> : is_typed_flags<SfxFilterFlags, 0x77bf157fL> {};
 }
 
 #define SFX_FILTER_NOTINSTALLED (SfxFilterFlags::MUSTINSTALL | SfxFilterFlags::CONSULTSERVICE)
diff --git a/include/sfx2/docfilt.hxx b/include/sfx2/docfilt.hxx
index 2e8cc62c177d..ceeae3cf980f 100644
--- a/include/sfx2/docfilt.hxx
+++ b/include/sfx2/docfilt.hxx
@@ -82,7 +82,10 @@ public:
     bool GetSupportsSigning() const { return bool(nFormatType & SfxFilterFlags::SUPPORTSSIGNING); }
     bool GetGpgEncryption() const { return bool(nFormatType & SfxFilterFlags::GPGENCRYPTION); }
     bool IsOwnTemplateFormat() const { return bool(nFormatType & SfxFilterFlags::TEMPLATEPATH); }
+    /// not our built-in format
     bool IsAlienFormat() const { return bool(nFormatType & SfxFilterFlags::ALIEN); }
+    /// an unusual/legacy file to be loading
+    bool IsExoticFormat() const { return bool(nFormatType & SfxFilterFlags::EXOTIC); }
     bool CanImport() const { return bool(nFormatType & SfxFilterFlags::IMPORT); }
     bool CanExport() const { return bool(nFormatType & SfxFilterFlags::EXPORT); }
     SfxFilterFlags  GetFilterFlags() const  { return nFormatType; }
diff --git a/include/sfx2/objsh.hxx b/include/sfx2/objsh.hxx
index 4bf859dadcc8..1f3f085f85ac 100644
--- a/include/sfx2/objsh.hxx
+++ b/include/sfx2/objsh.hxx
@@ -745,6 +745,9 @@ public:
 
     SAL_DLLPRIVATE void ImplSign( bool bScriptingContent = false );
     SAL_DLLPRIVATE bool QuerySaveSizeExceededModules_Impl( const css::uno::Reference< css::task::XInteractionHandler >& xHandler );
+    SAL_DLLPRIVATE bool QueryAllowExoticFormat_Impl( const css::uno::Reference< css::task::XInteractionHandler >& xHandler,
+                                                     const OUString& rURL,
+                                                     const OUString& rFilterUIName);
 
     SAL_DLLPRIVATE void CheckOut( );
     SAL_DLLPRIVATE void CancelCheckOut( );
diff --git a/offapi/UnoApi_offapi.mk b/offapi/UnoApi_offapi.mk
index 4330d93b77f6..da34ba0a74f7 100644
--- a/offapi/UnoApi_offapi.mk
+++ b/offapi/UnoApi_offapi.mk
@@ -2191,6 +2191,7 @@ $(eval $(call gb_UnoApi_add_idlfiles,offapi,com/sun/star/document,\
 	DocumentEvent \
 	EmptyUndoStackException \
 	EventObject \
+	ExoticFileLoadException \
 	FilterOptionsRequest \
 	LinkUpdateModes \
 	LockFileCorruptRequest \
diff --git a/offapi/com/sun/star/document/ExoticFileLoadException.idl b/offapi/com/sun/star/document/ExoticFileLoadException.idl
new file mode 100644
index 000000000000..e742f7edbea7
--- /dev/null
+++ b/offapi/com/sun/star/document/ExoticFileLoadException.idl
@@ -0,0 +1,34 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+#ifndef __com_sun_star_document_ExoticFileLoadException_idl__
+#define __com_sun_star_document_ExoticFileLoadException_idl__
+
+#include <com/sun/star/uno/Exception.idl>
+
+module com { module sun { module star { module document {
+
+/** An exception used to notify loading of an exotic file format
+    @since LibreOffice 6.1
+*/
+exception ExoticFileLoadException : ::com::sun::star::uno::Exception
+{
+    /** contains the URL of the document
+     */
+    string URL;
+
+    /** contains the UI name of the filter
+     */
+    string FilterUIName;
+};
+
+
+}; }; }; };
+
+#endif
+
diff --git a/officecfg/registry/schema/org/openoffice/Office/Common.xcs b/officecfg/registry/schema/org/openoffice/Office/Common.xcs
index 947067145fd0..9463ff5b7861 100644
--- a/officecfg/registry/schema/org/openoffice/Office/Common.xcs
+++ b/officecfg/registry/schema/org/openoffice/Office/Common.xcs
@@ -2438,6 +2438,29 @@
       <info>
         <desc>Contains security specific Office settings.</desc>
       </info>
+      <prop oor:name="LoadExoticFileFormats" oor:type="xs:int" oor:nillable="false">
+        <info>
+          <desc>Determines how exotic file formats should be handled.</desc>
+        </info>
+        <constraints>
+          <enumeration oor:value="0">
+            <info>
+              <desc>Refuse loading without question</desc>
+            </info>
+          </enumeration>
+          <enumeration oor:value="1">
+            <info>
+              <desc>Display a warning and let the user decide</desc>
+            </info>
+          </enumeration>
+          <enumeration oor:value="2">
+            <info>
+              <desc>Always load without question</desc>
+            </info>
+          </enumeration>
+        </constraints>
+        <value>2</value>
+      </prop>
       <prop oor:name="EnableExpertConfiguration" oor:type="xs:boolean" oor:nillable="false">
         <info>
           <desc>Determines if the user has access to the entire
diff --git a/sfx2/Library_sfx.mk b/sfx2/Library_sfx.mk
index e4c8ab9afe4a..2e2d6513319f 100644
--- a/sfx2/Library_sfx.mk
+++ b/sfx2/Library_sfx.mk
@@ -214,6 +214,7 @@ $(eval $(call gb_Library_add_exception_objects,sfx,\
     sfx2/source/doc/doctempl \
     sfx2/source/doc/doctemplates \
     sfx2/source/doc/doctemplateslocal \
+    sfx2/source/doc/exoticfileloadexception \
     sfx2/source/doc/frmdescr \
     sfx2/source/doc/graphhelp \
     sfx2/source/doc/guisaveas \
diff --git a/sfx2/source/doc/exoticfileloadexception.cxx b/sfx2/source/doc/exoticfileloadexception.cxx
new file mode 100644
index 000000000000..46b3c63edd65
--- /dev/null
+++ b/sfx2/source/doc/exoticfileloadexception.cxx
@@ -0,0 +1,42 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#include "exoticfileloadexception.hxx"
+
+#include <comphelper/interaction.hxx>
+#include <com/sun/star/document/ExoticFileLoadException.hpp>
+
+using namespace com::sun::star;
+
+ExoticFileLoadException::ExoticFileLoadException(const OUString& rURL,
+                                                 const OUString& rFilterUIName)
+{
+    document::ExoticFileLoadException aReq;
+    aReq.URL = rURL;
+    aReq.FilterUIName = rFilterUIName;
+
+    m_aRequest <<= aReq;
+
+    m_xAbort.set(uno::Reference<task::XInteractionAbort>(new comphelper::OInteractionAbort),
+                 uno::UNO_QUERY);
+    m_xApprove.set(uno::Reference<task::XInteractionApprove>(new comphelper::OInteractionApprove),
+                   uno::UNO_QUERY);
+    m_lContinuations.realloc(2);
+    m_lContinuations[0] = m_xApprove;
+    m_lContinuations[1] = m_xAbort;
+}
+
+bool ExoticFileLoadException::isApprove() const
+{
+    comphelper::OInteractionApprove* pBase
+        = static_cast<comphelper::OInteractionApprove*>(m_xApprove.get());
+    return pBase->wasSelected();
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sfx2/source/doc/exoticfileloadexception.hxx b/sfx2/source/doc/exoticfileloadexception.hxx
new file mode 100644
index 000000000000..3f8d480d8fb6
--- /dev/null
+++ b/sfx2/source/doc/exoticfileloadexception.hxx
@@ -0,0 +1,42 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+#ifndef INCLUDED_SFX2_EXOTICFILELOADEXCEPTION_HXX
+#define INCLUDED_SFX2_EXOTICFILELOADEXCEPTION_HXX
+
+#include <com/sun/star/task/XInteractionHandler.hpp>
+#include <cppuhelper/implbase.hxx>
+
+class ExoticFileLoadException : public cppu::WeakImplHelper<css::task::XInteractionRequest>
+{
+    // C++ interface
+public:
+    ExoticFileLoadException(const OUString& rURL, const OUString& rFilterUIName);
+    bool isApprove() const;
+
+    // UNO interface
+public:
+    virtual css::uno::Sequence<css::uno::Reference<css::task::XInteractionContinuation>>
+        SAL_CALL getContinuations() override
+    {
+        return m_lContinuations;
+    }
+    css::uno::Any SAL_CALL getRequest() override { return m_aRequest; }
+
+    // member
+private:
+    css::uno::Any m_aRequest;
+    css::uno::Sequence<css::uno::Reference<css::task::XInteractionContinuation>> m_lContinuations;
+    css::uno::Reference<css::task::XInteractionContinuation> m_xAbort;
+    css::uno::Reference<css::task::XInteractionContinuation> m_xApprove;
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sfx2/source/doc/objstor.cxx b/sfx2/source/doc/objstor.cxx
index feff5dfd91a1..13fb401a5e3a 100644
--- a/sfx2/source/doc/objstor.cxx
+++ b/sfx2/source/doc/objstor.cxx
@@ -81,6 +81,7 @@
 #include <unotools/saveopt.hxx>
 #include <unotools/useroptions.hxx>
 #include <unotools/pathoptions.hxx>
+#include <unotools/securityoptions.hxx>
 #include <tools/urlobj.hxx>
 #include <tools/diagnose_ex.h>
 #include <unotools/ucbhelper.hxx>
@@ -130,6 +131,7 @@
 #include <appbaslib.hxx>
 #include <appdata.hxx>
 #include "objstor.hxx"
+#include "exoticfileloadexception.hxx"
 
 using namespace ::com::sun::star;
 using namespace ::com::sun::star::container;
@@ -651,6 +653,11 @@ bool SfxObjectShell::DoLoad( SfxMedium *pMed )
         SetError( ERRCODE_IO_FILTERDISABLED );
     }
 
+    if ( pFilter && pFilter->IsExoticFormat() && !QueryAllowExoticFormat_Impl( getInteractionHandler(), aBaseURL, pMed->GetFilter()->GetUIName() ) )
+    {
+        SetError( ERRCODE_IO_ABORT );
+    }
+
     // initialize static language table so language-related extensions are learned before the document loads
     (void)SvtLanguageTable::GetLanguageEntryCount();
 
@@ -3557,7 +3564,35 @@ bool SfxObjectShell::QuerySaveSizeExceededModules_Impl( const uno::Reference< ta
     return true;
 }
 
-// comphelper::IEmbeddedHelper
+bool SfxObjectShell::QueryAllowExoticFormat_Impl( const uno::Reference< task::XInteractionHandler >& xHandler, const OUString& rURL, const OUString& rFilterUIName )
+{
+    if ( SvtSecurityOptions().isTrustedLocationUri( rURL ) )
+    {
+        // Always load from trusted location
+        return true;
+    }
+    if ( officecfg::Office::Common::Security::LoadExoticFileFormats::get() == 0 )
+    {
+        // Refuse loading without question
+        return false;
+    }
+    else if ( officecfg::Office::Common::Security::LoadExoticFileFormats::get() == 2 )
+    {
+        // Always load without question
+        return true;
+    }
+    else if ( officecfg::Office::Common::Security::LoadExoticFileFormats::get() == 1 && xHandler.is() )
+    {
+        // Display a warning and let the user decide
+        rtl::Reference<ExoticFileLoadException> xException(new ExoticFileLoadException( rURL, rFilterUIName ));
+        uno::Reference< task::XInteractionRequest > xReq( xException.get() );
+        xHandler->handle( xReq );
+        return xException.get()->isApprove();
+    }
+    // No interaction handler, default is to continue to load
+    return true;
+}
+
 uno::Reference< task::XInteractionHandler > SfxObjectShell::getInteractionHandler() const
 {
     uno::Reference< task::XInteractionHandler > xRet;
diff --git a/uui/inc/ids.hrc b/uui/inc/ids.hrc
index d5a418918ec5..84d409f083ef 100644
--- a/uui/inc/ids.hrc
+++ b/uui/inc/ids.hrc
@@ -34,6 +34,8 @@ const std::pair<const char*, ErrCode> RID_UUI_ERRHDL[] =
       ERRCODE_UUI_IO_TARGETALREADYEXISTS },
     { NC_("RID_UUI_ERRHDL", "You are about to save/export a password protected basic library containing module(s) \n$(ARG1)\nwhich are too large to store in binary format. If you wish users that don't have access to the library password to be able to run macros in those module(s) you must split those modules into a number of smaller modules. Do you wish to continue to save/export this library?"),
       ERRCODE_UUI_IO_MODULESIZEEXCEEDED },
+    { NC_("RID_UUI_ERRHDL", "Beware!\n\nYou are about to load a very unusual sort of file ($(ARG2)) from the URL:\n\n$(ARG1)\n\nAre you certain that this file is a legacy document created many years ago?"),
+      ERRCODE_UUI_IO_EXOTICFILEFORMAT },
     { NC_("RID_UUI_ERRHDL", "The data from $(ARG1) has an incorrect checksum."),
       ERRCODE_UUI_IO_BADCRC },
     { NC_("RID_UUI_ERRHDL", "The object $(ARG1) cannot be created in directory $(ARG2)."),
diff --git a/uui/inc/ids.hxx b/uui/inc/ids.hxx
index 2d3b6d4e7408..71beff973f02 100644
--- a/uui/inc/ids.hxx
+++ b/uui/inc/ids.hxx
@@ -86,6 +86,7 @@
 #define ERRCODE_UUI_LOCKING_NOT_LOCKED                          ErrCode(ErrCodeArea::Uui, 61)
 #define ERRCODE_UUI_LOCKING_LOCK_EXPIRED                        ErrCode(ErrCodeArea::Uui, 62)
 #define ERRCODE_UUI_CANNOT_ACTIVATE_FACTORY                     ErrCode(ErrCodeArea::Uui, 63)
+#define ERRCODE_UUI_IO_EXOTICFILEFORMAT                         ErrCode(ErrCodeArea::Uui, 64)
 
 #endif
 
diff --git a/uui/source/iahndl.cxx b/uui/source/iahndl.cxx
index 228ff20af632..6dbe7df63e76 100644
--- a/uui/source/iahndl.cxx
+++ b/uui/source/iahndl.cxx
@@ -26,6 +26,7 @@
 #include <com/sun/star/configuration/backend/StratumCreationException.hpp>
 #include <com/sun/star/container/XHierarchicalNameAccess.hpp>
 #include <com/sun/star/document/BrokenPackageRequest.hpp>
+#include <com/sun/star/document/ExoticFileLoadException.hpp>
 #include <com/sun/star/task/DocumentMacroConfirmationRequest.hpp>
 #include <com/sun/star/java/WrongJavaVersionException.hpp>
 #include <com/sun/star/lang/XInitialization.hpp>
@@ -434,6 +435,30 @@ UUIInteractionHelper::handleRequest_impl(
             return true;
         }
 
+        document::ExoticFileLoadException aExoticFileLoadException;
+        if (aAnyRequest >>= aExoticFileLoadException)
+        {
+            std::vector< OUString > aArguments;
+
+            if( !aExoticFileLoadException.URL.isEmpty() )
+            {
+                aArguments.push_back( aExoticFileLoadException.URL );
+            }
+            if( !aExoticFileLoadException.FilterUIName.isEmpty() )
+            {
+                aArguments.push_back( aExoticFileLoadException.FilterUIName );
+            }
+
+            handleErrorHandlerRequest( task::InteractionClassification_WARNING,
+                                       ERRCODE_UUI_IO_EXOTICFILEFORMAT,
+                                       aArguments,
+                                       rRequest->getContinuations(),
+                                       bObtainErrorStringOnly,
+                                       bHasErrorString,
+                                       rErrorString);
+            return true;
+        }
+
         ucb::NameClashException aNCException;
         if (aAnyRequest >>= aNCException)
         {


More information about the Libreoffice-commits mailing list