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

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