sw/qa/extras/ww8import/ww8import.cxx |    2 +-
 sw/source/ui/uno/swdetect.cxx        |   25 ++++++++++++++++++-------
 2 files changed, 19 insertions(+), 8 deletions(-)

New commits:
commit f657983a6ec7f79482efc3a0f70510e15b527670
Author:     Justin Luth <jl...@mail.com>
AuthorDate: Tue Sep 27 22:08:48 2022 -0400
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Fri Oct 14 09:33:18 2022 +0200

    tdf#125216 import filter: allow .doc renamed as .dot
    
    A LO 6.2.2 regression prevented .doc-as-.dot files to load,
    giving a "Read Error. This is not a valid WinWord6 file."
    
    Well, it is not a valid .dot file (because of some bit differences),
    but it is a valid .doc file.
    Since it was renamed to be treated as a template
    (requiring a save-as), we should treat it as that.
    
    Change-Id: I308375797e9dae3ca6d203fab520e91ee788325e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140687
    Tested-by: Jenkins
    Reviewed-by: Justin Luth <jl...@mail.com>
    (cherry picked from commit 6cec8ba33a28de7248861b2eecfc5034cbde9d37)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/140608
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/sw/qa/extras/ww8import/data/tdf120761_zOrder.doc 
b/sw/qa/extras/ww8import/data/tdf120761_zOrder.dot
similarity index 100%
rename from sw/qa/extras/ww8import/data/tdf120761_zOrder.doc
rename to sw/qa/extras/ww8import/data/tdf120761_zOrder.dot
diff --git a/sw/qa/extras/ww8import/ww8import.cxx 
b/sw/qa/extras/ww8import/ww8import.cxx
index 7eb0c9f6b221..8c77217c7610 100644
--- a/sw/qa/extras/ww8import/ww8import.cxx
+++ b/sw/qa/extras/ww8import/ww8import.cxx
@@ -275,7 +275,7 @@ CPPUNIT_TEST_FIXTURE(Test, testTdf110987)
 
 CPPUNIT_TEST_FIXTURE(Test, testTdf120761_zOrder)
 {
-    load(mpTestDocumentPath, "tdf120761_zOrder.doc");
+    load(mpTestDocumentPath, "tdf120761_zOrder.dot");
     //The blue shape was covering everything (highest zorder = 2) instead of 
the lowest(0)
     uno::Reference<drawing::XShape> xShape(getShapeByName(u"Picture 2"), 
uno::UNO_QUERY);
     CPPUNIT_ASSERT_EQUAL(sal_uInt32(0), getProperty<sal_uInt32>(xShape, 
"ZOrder"));
diff --git a/sw/source/ui/uno/swdetect.cxx b/sw/source/ui/uno/swdetect.cxx
index 9e354dedaf6b..83b7162ae2a0 100644
--- a/sw/source/ui/uno/swdetect.cxx
+++ b/sw/source/ui/uno/swdetect.cxx
@@ -24,6 +24,7 @@
 #include <com/sun/star/uno/XComponentContext.hpp>
 #include <sfx2/docfile.hxx>
 #include <sot/storage.hxx>
+#include <tools/urlobj.hxx>
 #include <unotools/mediadescriptor.hxx>
 
 using namespace ::com::sun::star;
@@ -102,19 +103,29 @@ OUString SAL_CALL SwFilterDetect::detect( Sequence< 
PropertyValue >& lDescriptor
                     // mis-detect it.
                     if ( bIsDetected && aTypeName == 
"writer_MS_Word_97_Vorlage" )
                     {
+                        // It is common practice to rename a .doc to .dot to 
make it a template.
+                        // Since we have detected a.doc-ish format, always 
accept .dot-named-files
+                        // as valid templates to avoid flagging this as an 
invalid .dot format..
+                        INetURLObject 
aParser(aMediaDesc.getUnpackedValueOrDefault(
+                            utl::MediaDescriptor::PROP_URL, OUString()));
+
                         // Super ugly hack, but we don't want to use the whole 
WW8Fib thing here in
                         // the swd library, apparently. We know (do we?) that 
the "aBits1" byte, as
                         // the variable is called in 
WW8Fib::WW8Fib(SvStream&,sal_uInt8,sal_uInt32),
                         // is at offset 10 in the WordDocument stream. The 
fDot bit is bit 0x01 of
                         // that byte.
-                        tools::SvRef<SotStorageStream> xWordDocument = 
aStorage->OpenSotStream("WordDocument", StreamMode::STD_READ);
-                        xWordDocument->Seek( 10 );
-                        if ( xWordDocument->Tell() == 10 )
+                        if (aParser.getExtension().toAsciiLowerCase() != "dot")
                         {
-                            sal_uInt8 aBits1;
-                            xWordDocument->ReadUChar( aBits1 );
-                            // Check fDot bit
-                            bIsDetected = ((aBits1 & 0x01) == 0x01);
+                            tools::SvRef<SotStorageStream> xWordDocument
+                                = aStorage->OpenSotStream("WordDocument", 
StreamMode::STD_READ);
+                            xWordDocument->Seek(10);
+                            if (xWordDocument->Tell() == 10)
+                            {
+                                sal_uInt8 aBits1;
+                                xWordDocument->ReadUChar(aBits1);
+                                // Check fDot bit
+                                bIsDetected = ((aBits1 & 0x01) == 0x01);
+                            }
                         }
                     }
                 }

Reply via email to