[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-5.1' - framework/source oox/source

Maxim Monastirsky momonasmon at gmail.com
Thu Dec 8 10:05:08 UTC 2016


 framework/source/loadenv/loadenv.cxx |    5 +++++
 oox/source/core/filterdetect.cxx     |   18 +++++++++++++-----
 2 files changed, 18 insertions(+), 5 deletions(-)

New commits:
commit 57983a4170559a5d45a28c5b3cb8c13393cfffff
Author: Maxim Monastirsky <momonasmon at gmail.com>
Date:   Wed Apr 27 16:19:13 2016 +0300

    tdf#80999 Canceling password prompt should abort detection
    
    ... instead of continuing the detection loop and being
    "detected" as plain text. The detection API will from now
    return a type based on the file extension only, which is
    far more useful than "plain text" anyway. Plus the media
    descriptor has a flag to indicate that the detection wasn't
    completed, which can be also used by the loading code to
    abort the loading process.
    
    Change-Id: Ida37e2687bd5cd86b5780620724e9bce82e11946
    Reviewed-on: https://gerrit.libreoffice.org/24428
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Maxim Monastirsky <momonasmon at gmail.com>
    (cherry picked from commit 579c2de3a88483eff0664d3a303b19cbd386db47)
    Reviewed-on: https://gerrit.libreoffice.org/31738
    Reviewed-by: Jan Holesovsky <kendy at collabora.com>
    Tested-by: Jan Holesovsky <kendy at collabora.com>

diff --git a/framework/source/loadenv/loadenv.cxx b/framework/source/loadenv/loadenv.cxx
index 0c8b56b..c8e4820 100644
--- a/framework/source/loadenv/loadenv.cxx
+++ b/framework/source/loadenv/loadenv.cxx
@@ -781,6 +781,11 @@ void LoadEnv::impl_detectTypeAndFilter()
     aWriteLock.clear();
     // <- SAFE
 
+    // We do have potentially correct type, but the detection process was aborted.
+    if (m_lMediaDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_ABORTED(), false))
+        throw LoadEnvException(
+            LoadEnvException::ID_UNSUPPORTED_CONTENT, "type detection aborted");
+
     // But the type isn't enough. For loading sometimes we need more information.
     // E.g. for our "_default" feature, where we recycle any frame which contains
     // and "Untitled" document, we must know if the new document is based on a template!
diff --git a/oox/source/core/filterdetect.cxx b/oox/source/core/filterdetect.cxx
index ede7849..ccae47b 100644
--- a/oox/source/core/filterdetect.cxx
+++ b/oox/source/core/filterdetect.cxx
@@ -387,11 +387,7 @@ OUString SAL_CALL FilterDetect::detect( Sequence< PropertyValue >& rMediaDescSeq
     OUString aFilterName;
     MediaDescriptor aMediaDescriptor( rMediaDescSeq );
 
-    /*  Check that the user has not chosen to abort detection, e.g. by hitting
-        'Cancel' in the password input dialog. This may happen because this
-        filter detection is used by different filters. */
-    bool bAborted = aMediaDescriptor.getUnpackedValueOrDefault( MediaDescriptor::PROP_ABORTED(), false );
-    if( !bAborted ) try
+    try
     {
         aMediaDescriptor.addInputStream();
 
@@ -420,6 +416,18 @@ OUString SAL_CALL FilterDetect::detect( Sequence< PropertyValue >& rMediaDescSeq
     }
     catch( const Exception& )
     {
+        if ( aMediaDescriptor.getUnpackedValueOrDefault( MediaDescriptor::PROP_ABORTED(), false ) )
+            /*  The user chose to abort detection, e.g. by hitting 'Cancel' in the password input dialog,
+                so we have to return non-empty type name to abort the detection loop. The loading code is
+                supposed to check whether the "Aborted" flag is present in the descriptor, and to not attempt
+                to actually load the file then.
+
+                The returned type name is the one we got as an input, which typically was detected by the flat
+                detection (i.e. by file extension), so normally that's the correct one. Also at this point we
+                already know that the file is OLE encrypted package, so trying with other type detectors doesn't
+                make much sense anyway.
+            */
+            aFilterName = aMediaDescriptor.getUnpackedValueOrDefault( MediaDescriptor::PROP_TYPENAME(), OUString() );
     }
 
     // write back changed media descriptor members


More information about the Libreoffice-commits mailing list