sw/qa/core/data/ooxml/pass/tdf96749.docx              |binary
 writerfilter/source/ooxml/OOXMLDocumentImpl.cxx       |   17 +++++++--
 writerfilter/source/ooxml/OOXMLFastContextHandler.cxx |   32 ++++++++++++++----
 3 files changed, 38 insertions(+), 11 deletions(-)

New commits:
commit 9876ffe934a21df1df4a457aa88aa8441243dba9
Author: Julien Nabet <serval2...@yahoo.fr>
Date:   Mon Dec 28 19:27:56 2015 +0100

    tdf#96749: deal with missing custom headers/footers in docx
    
    Some custom headers and footers are referenced in docx but aren't present.
    See https://bugs.documentfoundation.org/show_bug.cgi?id=96749#c1
    eg: 
warn:writerfilter:20417:1:writerfilter/source/filter/WriterFilter.cxx:214: 
WriterFilter::filter(): failed with exception
    Element does not exist and cannot be created: "header1.xml"
    
    See comment in bug: "The attached DOCX was generated by
    1C:Enterprise -- extremely popular monopoly business CRM in Russia,
    with huge userbase (millions of installations)."
    
    This is apparently not a fatal condition in MS Word, so all we need to
    do is to return when we hit such a problem (resolveEmbeddingsStream is
    a recursive function).
    
    Change-Id: I0e085a5f07dc6cc044bbd713e8f81d67dbe5d8b2
    Reviewed-on: https://gerrit.libreoffice.org/20993
    Reviewed-by: Caolán McNamara <caol...@redhat.com>
    Tested-by: Caolán McNamara <caol...@redhat.com>

diff --git a/sw/qa/core/data/ooxml/pass/tdf96749.docx 
b/sw/qa/core/data/ooxml/pass/tdf96749.docx
new file mode 100644
index 0000000..c7b79ee
Binary files /dev/null and b/sw/qa/core/data/ooxml/pass/tdf96749.docx differ
diff --git a/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx 
b/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx
index 6503fbd..ae8d8fe 100644
--- a/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx
+++ b/writerfilter/source/ooxml/OOXMLDocumentImpl.cxx
@@ -186,7 +186,7 @@ void OOXMLDocumentImpl::importSubStreamRelations(const 
OOXMLStream::Pointer_t& p
     OOXMLStream::Pointer_t cStream;
     try
     {
-       cStream = OOXMLDocumentFactory::createStream(pStream, nType);
+        cStream = OOXMLDocumentFactory::createStream(pStream, nType);
     }
     catch (uno::Exception const& e)
     {
@@ -763,9 +763,18 @@ void OOXMLDocumentImpl::resolveEmbeddingsStream(const 
OOXMLStream::Pointer_t& pS
                 }
                 if(bHeaderFooterFound)
                 {
-                    OOXMLStream::Pointer_t Stream = 
OOXMLDocumentFactory::createStream(pStream, streamType);
-                    if(Stream)
-                        resolveEmbeddingsStream(Stream);
+                    try
+                    {
+                        OOXMLStream::Pointer_t Stream = 
OOXMLDocumentFactory::createStream(pStream, streamType);
+                        if (Stream)
+                            resolveEmbeddingsStream(Stream);
+                    }
+                    catch (uno::Exception const& e)
+                    {
+                        SAL_INFO("writerfilter", "resolveEmbeddingsStream: 
can't find header/footer whilst "
+                               "resolving stream " << streamType << " : " << 
e.Message);
+                        return;
+                    }
                 }
 
                 beans::PropertyValue embeddingsTemp;
diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx 
b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
index a69cbc6..c6730eb 100644
--- a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
+++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
@@ -21,11 +21,13 @@
 #include <set>
 #include <comphelper/servicehelper.hxx>
 #include <com/sun/star/drawing/XShapes.hpp>
+#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
 #include <com/sun/star/xml/sax/FastShapeContextHandler.hpp>
 #include <ooxml/QNameToString.hxx>
 #include <ooxml/resourceids.hxx>
 #include <oox/token/namespaces.hxx>
 #include <comphelper/embeddedobjectcontainer.hxx>
+#include <cppuhelper/exc_hlp.hxx>
 #include <tools/globname.hxx>
 #include <comphelper/classids.hxx>
 #include <sfx2/sfxbasemodel.hxx>
@@ -930,18 +932,34 @@ void OOXMLFastContextHandlerProperties::lcl_endFastElement
 (Token_t Element)
     throw (uno::RuntimeException, xml::sax::SAXException, std::exception)
 {
-    endAction(Element);
-
-    if (mbResolve)
+    try
     {
-        if (isForwardEvents())
+        endAction(Element);
+
+        if (mbResolve)
         {
-            mpStream->props(mpPropertySet);
+            if (isForwardEvents())
+            {
+                mpStream->props(mpPropertySet);
+            }
+        }
+        else
+        {
+            sendPropertiesToParent();
         }
     }
-    else
+    catch (const uno::RuntimeException&)
+    {
+        throw;
+    }
+    catch (const xml::sax::SAXException&)
+    {
+        throw;
+    }
+    catch (const uno::Exception& e)
     {
-        sendPropertiesToParent();
+        auto a = cppu::getCaughtException();
+        throw lang::WrappedTargetRuntimeException(e.Message, e.Context, a);
     }
 }
 
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to