[Libreoffice-commits] libvisio.git: 7 commits - src/lib

David Tardon dtardon at redhat.com
Wed Jul 15 10:13:56 PDT 2015


 src/lib/VDXParser.cpp     |   12 +++++++-----
 src/lib/VSD5Parser.cpp    |    2 +-
 src/lib/VSD6Parser.cpp    |    2 +-
 src/lib/VSDParser.cpp     |    5 ++++-
 src/lib/VSDXMLHelper.cpp  |   18 ++++++++++--------
 src/lib/VSDXMetaData.cpp  |   15 ++++++++-------
 src/lib/VSDXParser.cpp    |    6 +++---
 src/lib/VSDXTheme.cpp     |   14 +++++++-------
 src/lib/VisioDocument.cpp |   24 +++++++++---------------
 9 files changed, 50 insertions(+), 48 deletions(-)

New commits:
commit 17b71055939e80ea83506c633b908ca831bd0fad
Author: David Tardon <dtardon at redhat.com>
Date:   Wed Jul 15 19:02:28 2015 +0200

    don't leak in case of exception
    
    Change-Id: Ib9eb9e02b678bc892b4cefd9fb793a06b2302879

diff --git a/src/lib/VDXParser.cpp b/src/lib/VDXParser.cpp
index 38b7a6c..1776de2 100644
--- a/src/lib/VDXParser.cpp
+++ b/src/lib/VDXParser.cpp
@@ -12,6 +12,7 @@
 #include <libxml/xmlstring.h>
 #include <librevenge-stream/librevenge-stream.h>
 #include <boost/algorithm/string.hpp>
+#include <boost/shared_ptr.hpp>
 #include "VDXParser.h"
 #include "libvisio_utils.h"
 #include "VSDContentCollector.h"
@@ -73,17 +74,18 @@ bool libvisio::VDXParser::processXmlDocument(librevenge::RVNGInputStream *input)
   if (!input)
     return false;
 
-  xmlTextReaderPtr reader = xmlReaderForStream(input, 0, 0, XML_PARSE_NOBLANKS|XML_PARSE_NOENT|XML_PARSE_NONET|XML_PARSE_RECOVER);
+  const boost::shared_ptr<xmlTextReader> reader(
+    xmlReaderForStream(input, 0, 0, XML_PARSE_NOBLANKS|XML_PARSE_NOENT|XML_PARSE_NONET|XML_PARSE_RECOVER),
+    xmlFreeTextReader);
   if (!reader)
     return false;
-  int ret = xmlTextReaderRead(reader);
+  int ret = xmlTextReaderRead(reader.get());
   while (1 == ret)
   {
-    processXmlNode(reader);
+    processXmlNode(reader.get());
 
-    ret = xmlTextReaderRead(reader);
+    ret = xmlTextReaderRead(reader.get());
   }
-  xmlFreeTextReader(reader);
 
   return true;
 }
diff --git a/src/lib/VSDXMLHelper.cpp b/src/lib/VSDXMLHelper.cpp
index 925e70b..b42b093 100644
--- a/src/lib/VSDXMLHelper.cpp
+++ b/src/lib/VSDXMLHelper.cpp
@@ -16,6 +16,7 @@
 #include <vector>
 #include <boost/algorithm/string.hpp>
 #include <boost/lexical_cast.hpp>
+#include <boost/shared_ptr.hpp>
 #include <libxml/xmlIO.h>
 #include <libxml/xmlstring.h>
 #include <librevenge-stream/librevenge-stream.h>
@@ -264,7 +265,9 @@ libvisio::VSDXRelationships::VSDXRelationships(librevenge::RVNGInputStream *inpu
 {
   if (input)
   {
-    shared_ptr<xmlTextReader> reader(xmlReaderForStream(input, 0, 0, XML_PARSE_NOBLANKS|XML_PARSE_NOENT|XML_PARSE_NONET|XML_PARSE_RECOVER), xmlFreeTextReader);
+    const boost::shared_ptr<xmlTextReader> reader(
+      xmlReaderForStream(input, 0, 0, XML_PARSE_NOBLANKS|XML_PARSE_NOENT|XML_PARSE_NONET|XML_PARSE_RECOVER),
+      xmlFreeTextReader);
     if (reader)
     {
       bool inRelationships = false;
diff --git a/src/lib/VSDXMetaData.cpp b/src/lib/VSDXMetaData.cpp
index 94b1f99..ffcad6e 100644
--- a/src/lib/VSDXMetaData.cpp
+++ b/src/lib/VSDXMetaData.cpp
@@ -11,6 +11,7 @@
 #include "VSDXMLTokenMap.h"
 #include "libvisio_utils.h"
 #include <string>
+#include <boost/shared_ptr.hpp>
 
 libvisio::VSDXMetaData::VSDXMetaData()
   : m_metaData()
@@ -115,35 +116,35 @@ bool libvisio::VSDXMetaData::parse(librevenge::RVNGInputStream *input)
   if (!input)
     return false;
 
-  xmlTextReaderPtr reader = xmlReaderForStream(input, 0, 0, XML_PARSE_NOBLANKS|XML_PARSE_NOENT|XML_PARSE_NONET);
+  const boost::shared_ptr<xmlTextReader> reader(
+    xmlReaderForStream(input, 0, 0, XML_PARSE_NOBLANKS|XML_PARSE_NOENT|XML_PARSE_NONET),
+    xmlFreeTextReader);
   if (!reader)
     return false;
 
   try
   {
-    int ret = xmlTextReaderRead(reader);
+    int ret = xmlTextReaderRead(reader.get());
     while (1 == ret)
     {
-      int tokenId = getElementToken(reader);
+      int tokenId = getElementToken(reader.get());
       switch (tokenId)
       {
       case XML_CP_COREPROPERTIES:
       case XML_PROPERTIES:
-        readCoreProperties(reader);
+        readCoreProperties(reader.get());
         break;
       default:
         break;
 
       }
-      ret = xmlTextReaderRead(reader);
+      ret = xmlTextReaderRead(reader.get());
     }
   }
   catch (...)
   {
-    xmlFreeTextReader(reader);
     return false;
   }
-  xmlFreeTextReader(reader);
   return true;
 }
 
diff --git a/src/lib/VSDXTheme.cpp b/src/lib/VSDXTheme.cpp
index f962105..142623f 100644
--- a/src/lib/VSDXTheme.cpp
+++ b/src/lib/VSDXTheme.cpp
@@ -65,34 +65,34 @@ bool libvisio::VSDXTheme::parse(librevenge::RVNGInputStream *input)
   if (!input)
     return false;
 
-  xmlTextReaderPtr reader = xmlReaderForStream(input, 0, 0, XML_PARSE_NOBLANKS|XML_PARSE_NOENT|XML_PARSE_NONET);
+  const shared_ptr<xmlTextReader> reader(
+    xmlReaderForStream(input, 0, 0, XML_PARSE_NOBLANKS|XML_PARSE_NOENT|XML_PARSE_NONET),
+    xmlFreeTextReader);
   if (!reader)
     return false;
 
   try
   {
-    int ret = xmlTextReaderRead(reader);
+    int ret = xmlTextReaderRead(reader.get());
     while (1 == ret)
     {
-      int tokenId = getElementToken(reader);
+      int tokenId = getElementToken(reader.get());
 
       switch (tokenId)
       {
       case XML_A_CLRSCHEME:
-        readClrScheme(reader);
+        readClrScheme(reader.get());
         break;
       default:
         break;
       }
-      ret = xmlTextReaderRead(reader);
+      ret = xmlTextReaderRead(reader.get());
     }
   }
   catch (...)
   {
-    xmlFreeTextReader(reader);
     return false;
   }
-  xmlFreeTextReader(reader);
   return true;
 }
 
diff --git a/src/lib/VisioDocument.cpp b/src/lib/VisioDocument.cpp
index 5b27404..ee7c758 100644
--- a/src/lib/VisioDocument.cpp
+++ b/src/lib/VisioDocument.cpp
@@ -8,6 +8,7 @@
  */
 
 #include <string>
+#include <boost/shared_ptr.hpp>
 #include <librevenge/librevenge.h>
 #include <libvisio/libvisio.h>
 #include "libvisio_utils.h"
@@ -245,56 +246,49 @@ static bool parseOpcVisioDocument(librevenge::RVNGInputStream *input, librevenge
 
 static bool isXmlVisioDocument(librevenge::RVNGInputStream *input)
 {
-  xmlTextReaderPtr reader = 0;
   try
   {
     input->seek(0, librevenge::RVNG_SEEK_SET);
-    reader = libvisio::xmlReaderForStream(input, 0, 0, XML_PARSE_NOBLANKS|XML_PARSE_NOENT|XML_PARSE_NONET|XML_PARSE_RECOVER);
+    const boost::shared_ptr<xmlTextReader> reader(
+      libvisio::xmlReaderForStream(input, 0, 0, XML_PARSE_NOBLANKS|XML_PARSE_NOENT|XML_PARSE_NONET|XML_PARSE_RECOVER),
+      xmlFreeTextReader);
     if (!reader)
       return false;
-    int ret = xmlTextReaderRead(reader);
-    while (ret == 1 && 1 != xmlTextReaderNodeType(reader))
-      ret = xmlTextReaderRead(reader);
+    int ret = xmlTextReaderRead(reader.get());
+    while (ret == 1 && 1 != xmlTextReaderNodeType(reader.get()))
+      ret = xmlTextReaderRead(reader.get());
     if (ret != 1)
     {
-      xmlFreeTextReader(reader);
       return false;
     }
-    const xmlChar *name = xmlTextReaderConstName(reader);
+    const xmlChar *name = xmlTextReaderConstName(reader.get());
     if (!name)
     {
-      xmlFreeTextReader(reader);
       return false;
     }
     if (!xmlStrEqual(name, BAD_CAST("VisioDocument")))
     {
-      xmlFreeTextReader(reader);
       return false;
     }
 
     // Checking the two possible namespaces of VDX documents. This may be a bit strict
     // and filter out some of third party VDX documents. If that happens, commenting out
     // this block could be an option.
-    const xmlChar *nsname = xmlTextReaderConstNamespaceUri(reader);
+    const xmlChar *nsname = xmlTextReaderConstNamespaceUri(reader.get());
     if (!nsname)
     {
-      xmlFreeTextReader(reader);
       return false;
     }
     if (!xmlStrEqual(nsname, BAD_CAST("urn:schemas-microsoft-com:office:visio"))
         && !xmlStrEqual(nsname, BAD_CAST("http://schemas.microsoft.com/visio/2003/core")))
     {
-      xmlFreeTextReader(reader);
       return false;
     }
 
-    xmlFreeTextReader(reader);
     return true;
   }
   catch (...)
   {
-    if (reader)
-      xmlFreeTextReader(reader);
     return false;
   }
 }
commit 5e66100518d8e7f63e296178c48b1fc56fa3b765
Author: David Tardon <dtardon at redhat.com>
Date:   Wed Jul 15 18:54:23 2015 +0200

    avoid memory leak
    
    Change-Id: Ifb59e5f916b23fb681452c45149e56730ff36a89

diff --git a/src/lib/VSDXMLHelper.cpp b/src/lib/VSDXMLHelper.cpp
index 582763e..925e70b 100644
--- a/src/lib/VSDXMLHelper.cpp
+++ b/src/lib/VSDXMLHelper.cpp
@@ -264,24 +264,24 @@ libvisio::VSDXRelationships::VSDXRelationships(librevenge::RVNGInputStream *inpu
 {
   if (input)
   {
-    xmlTextReaderPtr reader = xmlReaderForStream(input, 0, 0, XML_PARSE_NOBLANKS|XML_PARSE_NOENT|XML_PARSE_NONET|XML_PARSE_RECOVER);
+    shared_ptr<xmlTextReader> reader(xmlReaderForStream(input, 0, 0, XML_PARSE_NOBLANKS|XML_PARSE_NOENT|XML_PARSE_NONET|XML_PARSE_RECOVER), xmlFreeTextReader);
     if (reader)
     {
       bool inRelationships = false;
-      int ret = xmlTextReaderRead(reader);
+      int ret = xmlTextReaderRead(reader.get());
       while (ret == 1)
       {
-        const xmlChar *name = xmlTextReaderConstName(reader);
+        const xmlChar *name = xmlTextReaderConstName(reader.get());
         if (name)
         {
           if (xmlStrEqual(name, BAD_CAST("Relationships")))
           {
-            if (xmlTextReaderNodeType(reader) == 1)
+            if (xmlTextReaderNodeType(reader.get()) == 1)
             {
               // VSD_DEBUG_MSG(("Relationships ON\n"));
               inRelationships = true;
             }
-            else if (xmlTextReaderNodeType(reader) == 15)
+            else if (xmlTextReaderNodeType(reader.get()) == 15)
             {
               // VSD_DEBUG_MSG(("Relationships OFF\n"));
               inRelationships = false;
@@ -291,15 +291,14 @@ libvisio::VSDXRelationships::VSDXRelationships(librevenge::RVNGInputStream *inpu
           {
             if (inRelationships)
             {
-              VSDXRelationship relationship(reader);
+              VSDXRelationship relationship(reader.get());
               m_relsByType[relationship.getType()] = relationship;
               m_relsById[relationship.getId()] = relationship;
             }
           }
         }
-        ret = xmlTextReaderRead(reader);
+        ret = xmlTextReaderRead(reader.get());
       }
-      xmlFreeTextReader(reader);
     }
   }
 }
commit 1ffd6ef4ff54c47b65a78a44a9979083b54dba13
Author: David Tardon <dtardon at redhat.com>
Date:   Wed Jul 15 18:48:23 2015 +0200

    afl: avoid null pointer dereference
    
    Change-Id: I641e7ca93d903db3b2e211ec90e420dc249e162e

diff --git a/src/lib/VSD5Parser.cpp b/src/lib/VSD5Parser.cpp
index 95b0766..1f1cef0 100644
--- a/src/lib/VSD5Parser.cpp
+++ b/src/lib/VSD5Parser.cpp
@@ -132,7 +132,7 @@ void libvisio::VSD5Parser::handleChunkRecords(librevenge::RVNGInputStream *input
 void libvisio::VSD5Parser::readGeomList(librevenge::RVNGInputStream *input)
 {
   VSD_DEBUG_MSG(("VSD5Parser::readGeomList\n"));
-  if (!m_shape.m_geometries.empty() && m_currentGeometryList->empty())
+  if (!m_shape.m_geometries.empty() && m_currentGeometryList && m_currentGeometryList->empty())
     m_shape.m_geometries.erase(--m_currentGeomListCount);
   m_currentGeometryList = &m_shape.m_geometries[m_currentGeomListCount++];
 
commit 943728197d471f4a1554ff320ff42bf5cfaac324
Author: David Tardon <dtardon at redhat.com>
Date:   Wed Jul 15 18:45:57 2015 +0200

    afl: avoid null pointer dereference
    
    Change-Id: Ice2a9440ca6bfa4c032186a4a65d6ed2e537648a

diff --git a/src/lib/VSDParser.cpp b/src/lib/VSDParser.cpp
index 7c903ce..3cb284a 100644
--- a/src/lib/VSDParser.cpp
+++ b/src/lib/VSDParser.cpp
@@ -678,7 +678,7 @@ void libvisio::VSDParser::_handleLevelChange(unsigned level)
     return;
   if (level <= m_currentShapeLevel+1)
   {
-    if (!m_shape.m_geometries.empty() && m_currentGeometryList->empty())
+    if (!m_shape.m_geometries.empty() && m_currentGeometryList && m_currentGeometryList->empty())
     {
       m_shape.m_geometries.erase(--m_currentGeomListCount);
       m_currentGeometryList = 0;
commit db36f1a63b9d046f437e44072f43ff9bedcbd283
Author: David Tardon <dtardon at redhat.com>
Date:   Wed Jul 15 18:40:17 2015 +0200

    afl: avoid null dereference
    
    Change-Id: I37a3295a82bdc29fa38cf24b8d5005d992699214

diff --git a/src/lib/VSDXParser.cpp b/src/lib/VSDXParser.cpp
index 23fc541..9cb62e6 100644
--- a/src/lib/VSDXParser.cpp
+++ b/src/lib/VSDXParser.cpp
@@ -421,7 +421,7 @@ void libvisio::VSDXParser::processXmlNode(xmlTextReaderPtr reader)
         readShapeProperties(reader);
       else
       {
-        if (m_isStencilStarted)
+        if (m_isStencilStarted && m_currentStencil)
           m_currentStencil->addStencilShape(m_shape.m_shapeId, m_shape);
         else
           _flushShape();
@@ -432,7 +432,7 @@ void libvisio::VSDXParser::processXmlNode(xmlTextReaderPtr reader)
     }
     else if (XML_READER_TYPE_END_ELEMENT == tokenType)
     {
-      if (m_isStencilStarted)
+      if (m_isStencilStarted && m_currentStencil)
         m_currentStencil->addStencilShape(m_shape.m_shapeId, m_shape);
       else
       {
@@ -636,7 +636,7 @@ void libvisio::VSDXParser::readPageSheetProperties(xmlTextReaderPtr reader)
   }
   while ((XML_PAGESHEET != tokenId || XML_READER_TYPE_END_ELEMENT != tokenType) && 1 == ret);
 
-  if (m_isStencilStarted)
+  if (m_isStencilStarted && m_currentStencil)
   {
     m_currentStencil->m_shadowOffsetX = shadowOffsetX;
     m_currentStencil->m_shadowOffsetY = shadowOffsetY;
commit 75d144e106c82aeaa610be1279215b0a4d0b1c5b
Author: David Tardon <dtardon at redhat.com>
Date:   Wed Jul 15 18:39:02 2015 +0200

    afl: avoid null dereference
    
    Change-Id: I34cd4745be84a77ba2a380f0821712b8f439ccbc

diff --git a/src/lib/VSD6Parser.cpp b/src/lib/VSD6Parser.cpp
index 35e152c..9e845eb 100644
--- a/src/lib/VSD6Parser.cpp
+++ b/src/lib/VSD6Parser.cpp
@@ -234,7 +234,7 @@ void libvisio::VSD6Parser::readFillAndShadow(librevenge::RVNGInputStream *input)
   {
     double shadowOffsetX = 0.0;
     double shadowOffsetY = 0.0;
-    if (m_isStencilStarted)
+    if (m_isStencilStarted && m_currentStencil)
     {
       VSD_DEBUG_MSG(("Found stencil fill\n"));
       shadowOffsetX = m_currentStencil->m_shadowOffsetX;
commit f9286b5b5d183bbdb34a92e42d484992a3b3385e
Author: David Tardon <dtardon at redhat.com>
Date:   Wed Jul 15 17:24:10 2015 +0200

    afl: don't leave dangling pointer around
    
    Change-Id: I9ad2c1711954d8fe9164c8d51d288e1aa04c8372

diff --git a/src/lib/VSDParser.cpp b/src/lib/VSDParser.cpp
index 9e75485..7c903ce 100644
--- a/src/lib/VSDParser.cpp
+++ b/src/lib/VSDParser.cpp
@@ -679,7 +679,10 @@ void libvisio::VSDParser::_handleLevelChange(unsigned level)
   if (level <= m_currentShapeLevel+1)
   {
     if (!m_shape.m_geometries.empty() && m_currentGeometryList->empty())
+    {
       m_shape.m_geometries.erase(--m_currentGeomListCount);
+      m_currentGeometryList = 0;
+    }
     m_collector->collectShapesOrder(0, m_currentShapeLevel+2, m_shapeList.getShapesOrder());
     m_shapeList.clear();
 


More information about the Libreoffice-commits mailing list