[Libreoffice-commits] core.git: 3 commits - include/oox include/sal oox/source sax/README sax/source

Michael Stahl mstahl at redhat.com
Wed Sep 13 09:13:32 UTC 2017


 include/oox/vml/vmlshapecontainer.hxx |    8 ++++----
 include/oox/vml/vmlshapecontext.hxx   |    9 +++++----
 include/sal/log-areas.dox             |    1 +
 oox/source/vml/vmlshapecontainer.cxx  |    4 ++--
 oox/source/vml/vmlshapecontext.cxx    |   30 ++++++++++++++++++------------
 sax/README                            |   14 +++++++++++++-
 sax/source/fastparser/fastparser.cxx  |    6 +++++-
 7 files changed, 48 insertions(+), 24 deletions(-)

New commits:
commit 403c7729734ed1a545f0436e31c4d14a2724606d
Author: Michael Stahl <mstahl at redhat.com>
Date:   Wed Sep 13 11:05:31 2017 +0200

    sax: allow some debug logging in FastParser
    
    Multi-threading makes this difficult; have it print synchronously
    where it is in the input when setting:
    SAL_LOG="+INFO.sax.fastparser+WARN" SAX_DISABLE_THREADS=1
    
    Change-Id: I8c77974acb2b4d4e273fc9c0f273c345d8feb2ff

diff --git a/include/sal/log-areas.dox b/include/sal/log-areas.dox
index e99a05bbfbc9..d12ae1675bfe 100644
--- a/include/sal/log-areas.dox
+++ b/include/sal/log-areas.dox
@@ -421,6 +421,7 @@ certain functionality.
 @section sax
 
 @li @c sax.cppunit
+ at li @c sax.fastparser
 
 @section stoc
 
diff --git a/sax/README b/sax/README
index 0e1e6175f3f1..00ca0f1af5ae 100644
--- a/sax/README
+++ b/sax/README
@@ -8,3 +8,6 @@ UNO services for SAX parsing and C++ functions for XMLSchema-2 data types.
     + C++ wrapper for fast SAX parser
     + C++ XMLSchema-2 data type conversion helpers
 
+Multi-threading in FastParser can be disabled for debugging purposes with:
+SAX_DISABLE_THREADS=1 SAL_LOG="+INFO.sax.fastparser+WARN"
+
diff --git a/sax/source/fastparser/fastparser.cxx b/sax/source/fastparser/fastparser.cxx
index 8188724a91d9..a0cfc2f9e740 100644
--- a/sax/source/fastparser/fastparser.cxx
+++ b/sax/source/fastparser/fastparser.cxx
@@ -759,7 +759,8 @@ void FastSaxParserImpl::parseStream(const InputSource& maStructSource)
             rEntity.mxDocumentHandler->startDocument();
         }
 
-        rEntity.mbEnableThreads = (rEntity.maStructSource.aInputStream->available() > 10000);
+        rEntity.mbEnableThreads = rEntity.maStructSource.aInputStream->available() > 10000
+            && !getenv("SAX_DISABLE_THREADS");
 
         if (rEntity.mbEnableThreads)
         {
@@ -1199,7 +1200,10 @@ void FastSaxParserImpl::callbackStartElement(const xmlChar *localName , const xm
         if (rEntity.mbEnableThreads)
             produce();
         else
+        {
+            SAL_INFO("sax.fastparser", " startElement line " << mxDocumentLocator->getLineNumber() << " column " << mxDocumentLocator->getColumnNumber() << " " << prefix << ":" << localName);
             rEntity.startElement( &rEvent );
+        }
     }
     catch (const Exception&)
     {
commit 88c84e71e2559ec6d0b4f8c5101a149daa4a2b2b
Author: Michael Stahl <mstahl at redhat.com>
Date:   Wed Sep 13 10:48:38 2017 +0200

    tdf#112311 oox: fix UAF of std::shared_ptr
    
    OOXMLFastContextHandlerShape::sendShape() deletes the parent context's
    ShapeTypeContext::mrTypeModel.
    
    It looks like the sendShape() can't be delayed because writerfilter
    wants to import the v:textbox content into a text frame.
    
    Keep the shape alive until the end of the containing context.
    
    Not sure if it's going to process the v:fill element properly,
    but at lest valgrind is happy.
    
    (probably regression from CWS writerfilter32bugfixes01)
    
    Change-Id: Ifeab84751a1b20b2f272c4dd74b7097deb5eece0

diff --git a/include/oox/vml/vmlshapecontainer.hxx b/include/oox/vml/vmlshapecontainer.hxx
index 10c8e74094e0..ff39d5f7212c 100644
--- a/include/oox/vml/vmlshapecontainer.hxx
+++ b/include/oox/vml/vmlshapecontainer.hxx
@@ -61,10 +61,10 @@ public:
     Drawing&     getDrawing() { return mrDrawing; }
 
     /** Creates and returns a new shape template object. */
-    ShapeType&          createShapeType();
+    std::shared_ptr<ShapeType> createShapeType();
     /** Creates and returns a new shape object of the specified type. */
     template< typename ShapeT >
-    ShapeT&             createShape();
+    std::shared_ptr<ShapeT> createShape();
 
     /** Final processing after import of the drawing fragment. */
     void                finalizeFragmentImport();
@@ -123,11 +123,11 @@ private:
 
 
 template< typename ShapeT >
-ShapeT& ShapeContainer::createShape()
+std::shared_ptr<ShapeT> ShapeContainer::createShape()
 {
     std::shared_ptr< ShapeT > xShape( new ShapeT( mrDrawing ) );
     maShapes.push_back( xShape );
-    return *xShape;
+    return xShape;
 }
 
 template< typename Functor >
diff --git a/include/oox/vml/vmlshapecontext.hxx b/include/oox/vml/vmlshapecontext.hxx
index f73055b3355f..7243684f6350 100644
--- a/include/oox/vml/vmlshapecontext.hxx
+++ b/include/oox/vml/vmlshapecontext.hxx
@@ -99,7 +99,7 @@ class ShapeTypeContext : public ShapeContextBase
 public:
     explicit            ShapeTypeContext(
                             ::oox::core::ContextHandler2Helper const & rParent,
-                            ShapeType& rShapeType,
+                            std::shared_ptr<ShapeType> const& pShapeType,
                             const AttributeList& rAttribs );
 
     virtual ::oox::core::ContextHandlerRef
@@ -113,6 +113,7 @@ private:
     OptValue< OUString > decodeFragmentPath( const AttributeList& rAttribs, sal_Int32 nToken ) const;
 
 private:
+    std::shared_ptr<ShapeType> m_pShapeType;
     ShapeTypeModel&     mrTypeModel;
 };
 
@@ -122,7 +123,7 @@ class ShapeContext : public ShapeTypeContext
 public:
     explicit            ShapeContext(
                             ::oox::core::ContextHandler2Helper const & rParent,
-                            ShapeBase& rShape,
+                            std::shared_ptr<ShapeBase> pShape,
                             const AttributeList& rAttribs );
 
     virtual ::oox::core::ContextHandlerRef
@@ -155,7 +156,7 @@ class GroupShapeContext : public ShapeContext
 public:
     explicit            GroupShapeContext(
                             ::oox::core::ContextHandler2Helper const & rParent,
-                            GroupShape& rShape,
+                            std::shared_ptr<GroupShape> pShape,
                             const AttributeList& rAttribs );
 
     virtual ::oox::core::ContextHandlerRef
@@ -172,7 +173,7 @@ public:
     explicit            RectangleShapeContext(
                             ::oox::core::ContextHandler2Helper const & rParent,
                             const AttributeList& rAttribs,
-                            RectangleShape& rShape );
+                            std::shared_ptr<RectangleShape> pShape);
 
     virtual ::oox::core::ContextHandlerRef
                         onCreateContext( sal_Int32 nElement, const AttributeList& rAttribs ) override;
diff --git a/oox/source/vml/vmlshapecontainer.cxx b/oox/source/vml/vmlshapecontainer.cxx
index d2fea16ea195..366f2fdfbb6a 100644
--- a/oox/source/vml/vmlshapecontainer.cxx
+++ b/oox/source/vml/vmlshapecontainer.cxx
@@ -59,11 +59,11 @@ ShapeContainer::~ShapeContainer()
 {
 }
 
-ShapeType& ShapeContainer::createShapeType()
+std::shared_ptr<ShapeType> ShapeContainer::createShapeType()
 {
     std::shared_ptr< ShapeType > xShape( new ShapeType( mrDrawing ) );
     maTypes.push_back( xShape );
-    return *xShape;
+    return xShape;
 }
 
 void ShapeContainer::finalizeFragmentImport()
diff --git a/oox/source/vml/vmlshapecontext.cxx b/oox/source/vml/vmlshapecontext.cxx
index 84185d40ecfd..dc97726fd0cc 100644
--- a/oox/source/vml/vmlshapecontext.cxx
+++ b/oox/source/vml/vmlshapecontext.cxx
@@ -269,9 +269,12 @@ ContextHandlerRef ShapeContextBase::createShapeContext( ContextHandler2Helper co
     return nullptr;
 }
 
-ShapeTypeContext::ShapeTypeContext( ContextHandler2Helper const & rParent, ShapeType& rShapeType, const AttributeList& rAttribs ) :
-    ShapeContextBase( rParent ),
-    mrTypeModel( rShapeType.getTypeModel() )
+ShapeTypeContext::ShapeTypeContext(ContextHandler2Helper const & rParent,
+        std::shared_ptr<ShapeType> const& pShapeType,
+        const AttributeList& rAttribs)
+    : ShapeContextBase(rParent)
+    , m_pShapeType(pShapeType) // tdf#112311 keep it alive
+    , mrTypeModel( pShapeType->getTypeModel() )
 {
     // shape identifier and shape name
     bool bHasOspid = rAttribs.hasAttribute( O_TOKEN( spid ) );
@@ -444,10 +447,11 @@ void ShapeTypeContext::setStyle( const OUString& rStyle )
     }
 }
 
-ShapeContext::ShapeContext( ContextHandler2Helper const & rParent, ShapeBase& rShape, const AttributeList& rAttribs ) :
-    ShapeTypeContext( rParent, rShape, rAttribs ),
-    mrShape( rShape ),
-    mrShapeModel( rShape.getShapeModel() )
+ShapeContext::ShapeContext(ContextHandler2Helper const & rParent,
+        std::shared_ptr<ShapeBase> pShape, const AttributeList& rAttribs)
+    : ShapeTypeContext( rParent, pShape, rAttribs )
+    , mrShape( *pShape )
+    , mrShapeModel( pShape->getShapeModel() )
 {
     // collect shape specific attributes
     mrShapeModel.maType = rAttribs.getXString( XML_type, OUString() );
@@ -534,9 +538,10 @@ void ShapeContext::setVmlPath( const OUString& rPath )
         mrShapeModel.maVmlPath = rPath;
 }
 
-GroupShapeContext::GroupShapeContext( ContextHandler2Helper const & rParent, GroupShape& rShape, const AttributeList& rAttribs ) :
-    ShapeContext( rParent, rShape, rAttribs ),
-    mrShapes( rShape.getChildren() )
+GroupShapeContext::GroupShapeContext(ContextHandler2Helper const & rParent,
+        std::shared_ptr<GroupShape> pShape, const AttributeList& rAttribs)
+    : ShapeContext( rParent, pShape, rAttribs )
+    , mrShapes( pShape->getChildren() )
 {
 }
 
@@ -548,8 +553,9 @@ ContextHandlerRef GroupShapeContext::onCreateContext( sal_Int32 nElement, const
     return xContext.get() ? xContext : ShapeContext::onCreateContext( nElement, rAttribs );
 }
 
-RectangleShapeContext::RectangleShapeContext( ContextHandler2Helper const & rParent, const AttributeList& rAttribs, RectangleShape& rShape ) :
-    ShapeContext( rParent, rShape, rAttribs )
+RectangleShapeContext::RectangleShapeContext(ContextHandler2Helper const & rParent,
+        const AttributeList& rAttribs, std::shared_ptr<RectangleShape> pShape)
+    : ShapeContext( rParent, pShape, rAttribs )
 {
 }
 
commit b5368c913d8fe574ddaf2d5424ab48ffd0fefd56
Author: Michael Stahl <mstahl at redhat.com>
Date:   Tue Sep 12 16:16:26 2017 +0200

    sax: improve README
    
    Change-Id: Ide71867ca1ad3ae43c18159585df6d0dafcbe586

diff --git a/sax/README b/sax/README
index 5bd1d1d98381..0e1e6175f3f1 100644
--- a/sax/README
+++ b/sax/README
@@ -1 +1,10 @@
-Wrapper around expat using UNO.
+UNO services for SAX parsing and C++ functions for XMLSchema-2 data types.
+
+* source/expwrap:
+    string-based SAX parser UNO service wrapping expat
+* source/fastparser:
+    multi-threaded token-based SAX parser UNO service wrapping libxml2
+* source/tools:
+    + C++ wrapper for fast SAX parser
+    + C++ XMLSchema-2 data type conversion helpers
+


More information about the Libreoffice-commits mailing list