Blame SOURCES/0001-tdf-80999-Canceling-password-prompt-should-abort-det.patch

f325b2
From 307cf8f9a19bc768d28394cc183a3d8bf634b7de Mon Sep 17 00:00:00 2001
f325b2
From: Maxim Monastirsky <momonasmon@gmail.com>
f325b2
Date: Wed, 27 Apr 2016 16:19:13 +0300
f325b2
Subject: [PATCH] tdf#80999 Canceling password prompt should abort detection
f325b2
f325b2
... instead of continuing the detection loop and being
f325b2
"detected" as plain text. The detection API will from now
f325b2
return a type based on the file extension only, which is
f325b2
far more useful than "plain text" anyway. Plus the media
f325b2
descriptor has a flag to indicate that the detection wasn't
f325b2
completed, which can be also used by the loading code to
f325b2
abort the loading process.
f325b2
f325b2
Change-Id: Ida37e2687bd5cd86b5780620724e9bce82e11946
f325b2
Reviewed-on: https://gerrit.libreoffice.org/24428
f325b2
Tested-by: Jenkins <ci@libreoffice.org>
f325b2
Reviewed-by: Maxim Monastirsky <momonasmon@gmail.com>
f325b2
(cherry picked from commit 579c2de3a88483eff0664d3a303b19cbd386db47)
f325b2
---
f325b2
 framework/source/loadenv/loadenv.cxx |  5 +++++
f325b2
 oox/source/core/filterdetect.cxx     | 18 +++++++++++++-----
f325b2
 2 files changed, 18 insertions(+), 5 deletions(-)
f325b2
f325b2
diff --git a/framework/source/loadenv/loadenv.cxx b/framework/source/loadenv/loadenv.cxx
f325b2
index 4261971..05e7821 100644
f325b2
--- a/framework/source/loadenv/loadenv.cxx
f325b2
+++ b/framework/source/loadenv/loadenv.cxx
f325b2
@@ -789,6 +789,11 @@ void LoadEnv::impl_detectTypeAndFilter()
f325b2
     aWriteLock.clear();
f325b2
     // <- SAFE
f325b2
 
f325b2
+    // We do have potentially correct type, but the detection process was aborted.
f325b2
+    if (m_lMediaDescriptor.getUnpackedValueOrDefault(utl::MediaDescriptor::PROP_ABORTED(), false))
f325b2
+        throw LoadEnvException(
f325b2
+            LoadEnvException::ID_UNSUPPORTED_CONTENT, "type detection aborted");
f325b2
+
f325b2
     // But the type isn't enough. For loading sometimes we need more information.
f325b2
     // E.g. for our "_default" feature, where we recycle any frame which contains
f325b2
     // and "Untitled" document, we must know if the new document is based on a template!
f325b2
diff --git a/oox/source/core/filterdetect.cxx b/oox/source/core/filterdetect.cxx
f325b2
index d48d25c..94ea20e 100644
f325b2
--- a/oox/source/core/filterdetect.cxx
f325b2
+++ b/oox/source/core/filterdetect.cxx
f325b2
@@ -386,11 +386,7 @@ OUString SAL_CALL FilterDetect::detect( Sequence< PropertyValue >& rMediaDescSeq
f325b2
     OUString aFilterName;
f325b2
     MediaDescriptor aMediaDescriptor( rMediaDescSeq );
f325b2
 
f325b2
-    /*  Check that the user has not chosen to abort detection, e.g. by hitting
f325b2
-        'Cancel' in the password input dialog. This may happen because this
f325b2
-        filter detection is used by different filters. */
f325b2
-    bool bAborted = aMediaDescriptor.getUnpackedValueOrDefault( MediaDescriptor::PROP_ABORTED(), false );
f325b2
-    if( !bAborted ) try
f325b2
+    try
f325b2
     {
f325b2
         aMediaDescriptor.addInputStream();
f325b2
 
f325b2
@@ -419,6 +415,18 @@ OUString SAL_CALL FilterDetect::detect( Sequence< PropertyValue >& rMediaDescSeq
f325b2
     }
f325b2
     catch( const Exception& )
f325b2
     {
f325b2
+        if ( aMediaDescriptor.getUnpackedValueOrDefault( MediaDescriptor::PROP_ABORTED(), false ) )
f325b2
+            /*  The user chose to abort detection, e.g. by hitting 'Cancel' in the password input dialog,
f325b2
+                so we have to return non-empty type name to abort the detection loop. The loading code is
f325b2
+                supposed to check whether the "Aborted" flag is present in the descriptor, and to not attempt
f325b2
+                to actually load the file then.
f325b2
+
f325b2
+                The returned type name is the one we got as an input, which typically was detected by the flat
f325b2
+                detection (i.e. by file extension), so normally that's the correct one. Also at this point we
f325b2
+                already know that the file is OLE encrypted package, so trying with other type detectors doesn't
f325b2
+                make much sense anyway.
f325b2
+            */
f325b2
+            aFilterName = aMediaDescriptor.getUnpackedValueOrDefault( MediaDescriptor::PROP_TYPENAME(), OUString() );
f325b2
     }
f325b2
 
f325b2
     // write back changed media descriptor members
f325b2
-- 
f325b2
2.9.3
f325b2