1. mst
  2. ooo340

Commits

Frank Schoenheit [fs]  committed 3ba1d8d

fs34b: added some diagnostics, so next time a bug like #i117507# happens, we will not - at least in a non-product build - silently ignore it

  • Participants
  • Parent commits 08b33ea
  • Branches default

Comments (0)

Files changed (1)

File forms/source/xforms/submission/serialization_app_xml.cxx

View file
  • Ignore whitespace
 /*************************************************************************
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- * 
+ *
  * Copyright 2000, 2010 Oracle and/or its affiliates.
  *
  * OpenOffice.org - a multi-platform office productivity suite
 #include "serialization.hxx"
 #include "serialization_app_xml.hxx"
 
-#include <unotools/processfactory.hxx>
 #include <com/sun/star/xml/dom/XNode.hpp>
 #include <com/sun/star/xml/dom/XDocument.hpp>
 #include <com/sun/star/xml/dom/XNodeList.hpp>
 #include <com/sun/star/lang/XUnoTunnel.hpp>
 #include <com/sun/star/xml/xpath/XPathObjectType.hpp>
 
+#include <tools/diagnose_ex.h>
+#include <unotools/processfactory.hxx>
+
 #include <libxml/tree.h>
 
+#include <limits>
+
 CSerializationAppXML::CSerializationAppXML()
     : m_aFactory(utl::getProcessServiceFactory())
-    , m_aPipe(CSS::uno::Reference< CSS::io::XOutputStream > (m_aFactory->createInstance( 
+    , m_aPipe(CSS::uno::Reference< CSS::io::XOutputStream > (m_aFactory->createInstance(
         rtl::OUString::createFromAscii("com.sun.star.io.Pipe")), CSS::uno::UNO_QUERY))
 {
     OSL_ENSURE(m_aPipe.is(), "cannot create Pipe");
 }
 
-CSS::uno::Reference< CSS::io::XInputStream > 
+CSS::uno::Reference< CSS::io::XInputStream >
 CSerializationAppXML::getInputStream()
 {
     // The pipes output is provided through it's
     return CSS::uno::Reference< CSS::io::XInputStream >(m_aPipe, CSS::uno::UNO_QUERY);
 }
 
-void 
+void
 CSerializationAppXML::serialize_node(const CSS::uno::Reference< CSS::xml::dom::XNode >& rNode)
 {
     CSS::uno::Reference< CSS::xml::dom::XNode > aNode = rNode;
     {
         CSS::uno::Reference< CSS::xml::dom::XDocument > aDoc(rNode, CSS::uno::UNO_QUERY_THROW);
         aNode = CSS::uno::Reference< CSS::xml::dom::XNode >(aDoc->getDocumentElement(), CSS::uno::UNO_QUERY_THROW);
-    } 
-    if (aNode->getNodeType() != CSS::xml::dom::NodeType_ELEMENT_NODE)
-        return;
+    }
+    ENSURE_OR_RETURN_VOID( aNode->getNodeType() == CSS::xml::dom::NodeType_ELEMENT_NODE,
+        "CSerializationAppXML::serialize_node: invalid node type!" );
 
     // clone the node to a new document and serialize that document
-    CSS::uno::Reference< CSS::lang::XUnoTunnel > aTunnel(aNode, CSS::uno::UNO_QUERY);
-    if (aTunnel.is()) 
+    CSS::uno::Reference< CSS::lang::XUnoTunnel > xTunnel( aNode, CSS::uno::UNO_QUERY );
+    ENSURE_OR_RETURN_VOID( xTunnel.is(), "CSerializationAppXML::serialize_node: unknown implementation, cannot serialize!" );
+
+    xmlNodePtr aNodePtr = reinterpret_cast< xmlNodePtr >( xTunnel->getSomething(CSS::uno::Sequence< sal_Int8 >()) );
+    ENSURE_OR_RETURN_VOID( aNodePtr != NULL, "CSerializationAppXML::serialize_node: unable to obtain the xmlNodePtr!" );
+
+    xmlDocPtr aDocPtr = xmlNewDoc((xmlChar*)"1.0");
+    ENSURE_OR_RETURN_VOID( aDocPtr != NULL, "CSerializationAppXML::serialize_node: unable to create a temporary doc!" );
+
+    xmlNodePtr aDocNodePtr = xmlDocCopyNode(aNodePtr, aDocPtr, 1);
+    if (aDocNodePtr != NULL)
     {
-        xmlNodePtr aNodePtr = reinterpret_cast< xmlNodePtr >( aTunnel->getSomething(CSS::uno::Sequence< sal_Int8 >()) );
-        xmlDocPtr aDocPtr = xmlNewDoc((xmlChar*)"1.0");
-        xmlNodePtr aDocNodePtr = xmlDocCopyNode(aNodePtr, aDocPtr, 1);
-        if (aDocNodePtr != NULL) {
-            xmlAddChild((xmlNodePtr)aDocPtr, aDocNodePtr);
-            xmlChar *buffer = NULL;
-            sal_Int32 size = 0;
-            xmlDocDumpMemory(aDocPtr, &buffer, (int*)&size);
-        
-            // write the xml into the pipe through it's XOutputStream interface
-            m_aPipe->writeBytes(CSS::uno::Sequence< sal_Int8 >((sal_Int8*)buffer, size));            
-            xmlFree(buffer);
+        xmlAddChild( (xmlNodePtr)aDocPtr, aDocNodePtr );
+
+        xmlChar *buffer = NULL;
+        int size = 0;
+        xmlDocDumpMemory( aDocPtr, &buffer, &size );
+
+        if ( size > ::std::numeric_limits< sal_Int32 >::max() )
+        {
+            OSL_ENSURE( false, "CSerializationAppXML::serialize_node: document too large, doesn't fit into a UNO sequence!" );
+            size = ::std::numeric_limits< sal_Int32 >::max();
         }
 
-    } else {
-        // can't get tunnel to native backend
-        // logic for generic implementation could be implemented here...
-        OSL_ENSURE(sal_False, "unkown dom implementation, cannot serialize");
-        return;
+        // write the xml into the pipe through it's XOutputStream interface
+        m_aPipe->writeBytes(CSS::uno::Sequence< sal_Int8 >((sal_Int8*)buffer, size));
+        xmlFree(buffer);
     }
+    xmlFreeDoc( aDocPtr );
 }
 
 /*
 
 void
 CSerializationAppXML::serialize()
-{    
+{
     if (!m_aFragment.is()) return;
 
     CSS::uno::Reference< CSS::xml::dom::XNode > cur = m_aFragment->getFirstChild();