[Libreoffice-commits] core.git: svgio/inc svgio/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri Aug 31 07:27:38 UTC 2018


 svgio/inc/svgstyleattributes.hxx              |    2 
 svgio/source/svgreader/svgstyleattributes.cxx |  184 +++++++++++++-------------
 2 files changed, 94 insertions(+), 92 deletions(-)

New commits:
commit 1fe8479e5ba4ec092d6dc6d88a1edd5fb4487542
Author:     Caolán McNamara <caolanm at redhat.com>
AuthorDate: Thu Aug 30 14:05:20 2018 +0100
Commit:     Caolán McNamara <caolanm at redhat.com>
CommitDate: Fri Aug 31 09:27:10 2018 +0200

    tdf#119557 style hierarchy isn't stable so looping check fails falsely
    
    Given the css stuff a given style can end up with itself as a grandparent but
    then the css mutates things so it doesn't loop around to give itself as a
    grandgrandparent.
    
    So undo the loop detection check and turn it into a parse depth test
    instead with an arbitrary, but high, level
    
    Change-Id: If28684ad2b2adc664bc2da6b176b93248b377162
    Reviewed-on: https://gerrit.libreoffice.org/59813
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/svgio/inc/svgstyleattributes.hxx b/svgio/inc/svgstyleattributes.hxx
index 44f4d35ab9b4..a024dc68b789 100644
--- a/svgio/inc/svgstyleattributes.hxx
+++ b/svgio/inc/svgstyleattributes.hxx
@@ -231,7 +231,7 @@ namespace svgio
             BaselineShift               maBaselineShift;
             SvgNumber                   maBaselineShiftNumber;
 
-            mutable bool                mbResolvingParent;
+            mutable std::vector<sal_uInt16> maResolvingParent;
 
             // defines if this attributes are part of a ClipPath. If yes,
             // rough geometry will be created on decomposition by patching
diff --git a/svgio/source/svgreader/svgstyleattributes.cxx b/svgio/source/svgreader/svgstyleattributes.cxx
index 8e6d9ea49fef..5f5d9df13584 100644
--- a/svgio/source/svgreader/svgstyleattributes.cxx
+++ b/svgio/source/svgreader/svgstyleattributes.cxx
@@ -43,6 +43,8 @@
 #include <drawinglayer/primitive2d/maskprimitive2d.hxx>
 #include <drawinglayer/primitive2d/pagehierarchyprimitive2d.hxx>
 
+const int nStyleDepthLimit = 1024;
+
 namespace svgio
 {
     namespace svgreader
@@ -1292,7 +1294,7 @@ namespace svgio
             maClipRule(FillRule_nonzero),
             maBaselineShift(BaselineShift_Baseline),
             maBaselineShiftNumber(0),
-            mbResolvingParent(false),
+            maResolvingParent(30, 0),
             mbIsClipPathContent(SVGTokenClipPathNode == mrOwner.getType()),
             mbStrokeDasharraySet(false)
         {
@@ -2032,11 +2034,11 @@ namespace svgio
             {
                 const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle();
 
-                if (pSvgStyleAttributes && !mbResolvingParent)
+                if (pSvgStyleAttributes && maResolvingParent[0] < nStyleDepthLimit)
                 {
-                    mbResolvingParent = true;
+                    ++maResolvingParent[0];
                     const basegfx::BColor* pFill = pSvgStyleAttributes->getFill();
-                    mbResolvingParent = false;
+                    --maResolvingParent[0];
 
                     if(mbIsClipPathContent)
                     {
@@ -2077,11 +2079,11 @@ namespace svgio
             {
                 const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle();
 
-                if (pSvgStyleAttributes && !mbResolvingParent)
+                if (pSvgStyleAttributes && maResolvingParent[1] < nStyleDepthLimit)
                 {
-                    mbResolvingParent = true;
+                    ++maResolvingParent[1];
                     auto ret = pSvgStyleAttributes->getStroke();
-                    mbResolvingParent = false;
+                    --maResolvingParent[1];
                     return ret;
                 }
             }
@@ -2111,11 +2113,11 @@ namespace svgio
             {
                 const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle();
 
-                if (pSvgStyleAttributes && !mbResolvingParent)
+                if (pSvgStyleAttributes && maResolvingParent[2] < nStyleDepthLimit)
                 {
-                    mbResolvingParent = true;
+                    ++maResolvingParent[2];
                     auto ret = pSvgStyleAttributes->getSvgGradientNodeFill();
-                    mbResolvingParent = false;
+                    --maResolvingParent[2];
                     return ret;
                 }
             }
@@ -2133,11 +2135,11 @@ namespace svgio
             {
                 const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle();
 
-                if (pSvgStyleAttributes && !mbResolvingParent)
+                if (pSvgStyleAttributes && maResolvingParent[3] < nStyleDepthLimit)
                 {
-                    mbResolvingParent = true;
+                    ++maResolvingParent[3];
                     auto ret = pSvgStyleAttributes->getSvgGradientNodeStroke();
-                    mbResolvingParent = false;
+                    --maResolvingParent[3];
                     return ret;
                 }
             }
@@ -2155,11 +2157,11 @@ namespace svgio
             {
                 const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle();
 
-                if (pSvgStyleAttributes && !mbResolvingParent)
+                if (pSvgStyleAttributes && maResolvingParent[4] < nStyleDepthLimit)
                 {
-                    mbResolvingParent = true;
+                    ++maResolvingParent[4];
                     auto ret = pSvgStyleAttributes->getSvgPatternNodeFill();
-                    mbResolvingParent = false;
+                    --maResolvingParent[4];
                     return ret;
                 }
             }
@@ -2177,11 +2179,11 @@ namespace svgio
             {
                 const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle();
 
-                if (pSvgStyleAttributes && !mbResolvingParent)
+                if (pSvgStyleAttributes && maResolvingParent[5] < nStyleDepthLimit)
                 {
-                    mbResolvingParent = true;
+                    ++maResolvingParent[5];
                     auto ret = pSvgStyleAttributes->getSvgPatternNodeStroke();
-                    mbResolvingParent = false;
+                    --maResolvingParent[5];
                     return ret;
                 }
             }
@@ -2198,11 +2200,11 @@ namespace svgio
 
             const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle();
 
-            if (pSvgStyleAttributes && !mbResolvingParent)
+            if (pSvgStyleAttributes && maResolvingParent[6] < nStyleDepthLimit)
             {
-                mbResolvingParent = true;
+                ++maResolvingParent[6];
                 auto ret = pSvgStyleAttributes->getStrokeWidth();
-                mbResolvingParent = false;
+                --maResolvingParent[6];
                 return ret;
             }
 
@@ -2235,11 +2237,11 @@ namespace svgio
 
             const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle();
 
-            if (pSvgStyleAttributes && !mbResolvingParent)
+            if (pSvgStyleAttributes && maResolvingParent[7] < nStyleDepthLimit)
             {
-                mbResolvingParent = true;
+                ++maResolvingParent[7];
                 auto ret = pSvgStyleAttributes->getFillOpacity();
-                mbResolvingParent = false;
+                --maResolvingParent[7];
                 return ret;
             }
 
@@ -2256,11 +2258,11 @@ namespace svgio
 
             const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle();
 
-            if (pSvgStyleAttributes && !mbResolvingParent)
+            if (pSvgStyleAttributes && maResolvingParent[8] < nStyleDepthLimit)
             {
-                mbResolvingParent = true;
+                ++maResolvingParent[8];
                 auto ret = pSvgStyleAttributes->getOpacity();
-                mbResolvingParent = false;
+                --maResolvingParent[8];
                 return ret;
             }
 
@@ -2274,11 +2276,11 @@ namespace svgio
             {
                 const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle();
 
-                if (pSvgStyleAttributes && !mbResolvingParent)
+                if (pSvgStyleAttributes && maResolvingParent[9] < nStyleDepthLimit)
                 {
-                    mbResolvingParent = true;
+                    ++maResolvingParent[9];
                     auto ret = pSvgStyleAttributes->getVisibility();
-                    mbResolvingParent = false;
+                    --maResolvingParent[9];
                     return ret;
                 }
                 //default is Visible
@@ -2327,11 +2329,11 @@ namespace svgio
 
             const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle();
 
-            if (pSvgStyleAttributes && !mbResolvingParent)
+            if (pSvgStyleAttributes && maResolvingParent[10] < nStyleDepthLimit)
             {
-                mbResolvingParent = true;
+                ++maResolvingParent[10];
                 auto ret = pSvgStyleAttributes->getFillRule();
-                mbResolvingParent = false;
+                --maResolvingParent[10];
                 return ret;
             }
 
@@ -2353,11 +2355,11 @@ namespace svgio
 
             const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle();
 
-            if (pSvgStyleAttributes && !mbResolvingParent)
+            if (pSvgStyleAttributes && maResolvingParent[11] < nStyleDepthLimit)
             {
-                mbResolvingParent = true;
+                ++maResolvingParent[11];
                 const SvgNumberVector& ret = pSvgStyleAttributes->getStrokeDasharray();
-                mbResolvingParent = false;
+                --maResolvingParent[11];
                 return ret;
             }
 
@@ -2374,11 +2376,11 @@ namespace svgio
 
             const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle();
 
-            if (pSvgStyleAttributes && !mbResolvingParent)
+            if (pSvgStyleAttributes && maResolvingParent[12] < nStyleDepthLimit)
             {
-                mbResolvingParent = true;
+                ++maResolvingParent[12];
                 auto ret = pSvgStyleAttributes->getStrokeDashOffset();
-                mbResolvingParent = false;
+                --maResolvingParent[12];
                 return ret;
             }
 
@@ -2395,11 +2397,11 @@ namespace svgio
 
             const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle();
 
-            if (pSvgStyleAttributes && !mbResolvingParent)
+            if (pSvgStyleAttributes && maResolvingParent[13] < nStyleDepthLimit)
             {
-                mbResolvingParent = true;
+                ++maResolvingParent[13];
                 auto ret = pSvgStyleAttributes->getStrokeLinecap();
-                mbResolvingParent = false;
+                --maResolvingParent[13];
                 return ret;
             }
 
@@ -2416,11 +2418,11 @@ namespace svgio
 
             const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle();
 
-            if (pSvgStyleAttributes && !mbResolvingParent)
+            if (pSvgStyleAttributes && maResolvingParent[14] < nStyleDepthLimit)
             {
-                mbResolvingParent = true;
+                ++maResolvingParent[14];
                 auto ret = pSvgStyleAttributes->getStrokeLinejoin();
-                mbResolvingParent = false;
+                --maResolvingParent[14];
                 return ret;
             }
 
@@ -2437,11 +2439,11 @@ namespace svgio
 
             const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle();
 
-            if (pSvgStyleAttributes && !mbResolvingParent)
+            if (pSvgStyleAttributes && maResolvingParent[15] < nStyleDepthLimit)
             {
-                mbResolvingParent = true;
+                ++maResolvingParent[15];
                 auto ret = pSvgStyleAttributes->getStrokeMiterLimit();
-                mbResolvingParent = false;
+                --maResolvingParent[15];
                 return ret;
             }
 
@@ -2458,11 +2460,11 @@ namespace svgio
 
             const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle();
 
-            if (pSvgStyleAttributes && !mbResolvingParent)
+            if (pSvgStyleAttributes && maResolvingParent[16] < nStyleDepthLimit)
             {
-                mbResolvingParent = true;
+                ++maResolvingParent[16];
                 auto ret = pSvgStyleAttributes->getStrokeOpacity();
-                mbResolvingParent = false;
+                --maResolvingParent[16];
                 return ret;
             }
 
@@ -2479,11 +2481,11 @@ namespace svgio
 
             const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle();
 
-            if (pSvgStyleAttributes && !mbResolvingParent)
+            if (pSvgStyleAttributes && maResolvingParent[17] < nStyleDepthLimit)
             {
-                mbResolvingParent = true;
+                ++maResolvingParent[17];
                 const SvgStringVector& ret = pSvgStyleAttributes->getFontFamily();
-                mbResolvingParent = false;
+                --maResolvingParent[17];
                 return ret;
             }
 
@@ -2619,11 +2621,11 @@ namespace svgio
 
             const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle();
 
-            if (pSvgStyleAttributes && !mbResolvingParent)
+            if (pSvgStyleAttributes && maResolvingParent[18] < nStyleDepthLimit)
             {
-                mbResolvingParent = true;
+                ++maResolvingParent[18];
                 FontStretch aInherited = pSvgStyleAttributes->getFontStretch();
-                mbResolvingParent = false;
+                --maResolvingParent[18];
 
                 if(FontStretch_wider == maFontStretch)
                 {
@@ -2650,11 +2652,11 @@ namespace svgio
 
             const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle();
 
-            if (pSvgStyleAttributes && !mbResolvingParent)
+            if (pSvgStyleAttributes && maResolvingParent[19] < nStyleDepthLimit)
             {
-                mbResolvingParent = true;
+                ++maResolvingParent[19];
                 auto ret = pSvgStyleAttributes->getFontStyle();
-                mbResolvingParent = false;
+                --maResolvingParent[19];
                 return ret;
             }
 
@@ -2674,11 +2676,11 @@ namespace svgio
 
             const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle();
 
-            if (pSvgStyleAttributes && !mbResolvingParent)
+            if (pSvgStyleAttributes && maResolvingParent[20] < nStyleDepthLimit)
             {
-                mbResolvingParent = true;
+                ++maResolvingParent[20];
                 FontWeight aInherited = pSvgStyleAttributes->getFontWeight();
-                mbResolvingParent = false;
+                --maResolvingParent[20];
 
                 if(FontWeight_bolder == maFontWeight)
                 {
@@ -2705,11 +2707,11 @@ namespace svgio
 
             const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle();
 
-            if (pSvgStyleAttributes && !mbResolvingParent)
+            if (pSvgStyleAttributes && maResolvingParent[21] < nStyleDepthLimit)
             {
-                mbResolvingParent = true;
+                ++maResolvingParent[21];
                 auto ret = pSvgStyleAttributes->getTextAlign();
-                mbResolvingParent = false;
+                --maResolvingParent[21];
                 return ret;
             }
 
@@ -2726,11 +2728,11 @@ namespace svgio
 
             const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle();
 
-            if (pSvgStyleAttributes && !mbResolvingParent)
+            if (pSvgStyleAttributes && maResolvingParent[22] < nStyleDepthLimit)
             {
-                mbResolvingParent = true;
+                ++maResolvingParent[22];
                 auto ret = pSvgStyleAttributes->getTextDecorationDefiningSvgStyleAttributes();
-                mbResolvingParent = false;
+                --maResolvingParent[22];
                 return ret;
             }
 
@@ -2762,11 +2764,11 @@ namespace svgio
 
             const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle();
 
-            if (pSvgStyleAttributes && !mbResolvingParent)
+            if (pSvgStyleAttributes && maResolvingParent[23] < nStyleDepthLimit)
             {
-                mbResolvingParent = true;
+                ++maResolvingParent[23];
                 auto ret = pSvgStyleAttributes->getTextAnchor();
-                mbResolvingParent = false;
+                --maResolvingParent[23];
                 return ret;
             }
 
@@ -2792,11 +2794,11 @@ namespace svgio
             {
                 const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle();
 
-                if (pSvgStyleAttributes && !mbResolvingParent)
+                if (pSvgStyleAttributes && maResolvingParent[24] < nStyleDepthLimit)
                 {
-                    mbResolvingParent = true;
+                    ++maResolvingParent[24];
                     auto ret = pSvgStyleAttributes->getColor();
-                    mbResolvingParent = false;
+                    --maResolvingParent[24];
                     return ret;
                 }
             }
@@ -2833,11 +2835,11 @@ namespace svgio
 
             const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle();
 
-            if (pSvgStyleAttributes && !pSvgStyleAttributes->maMaskXLink.isEmpty() && !mbResolvingParent)
+            if (pSvgStyleAttributes && !pSvgStyleAttributes->maMaskXLink.isEmpty() && maResolvingParent[25] < nStyleDepthLimit)
             {
-                mbResolvingParent = true;
+                ++maResolvingParent[25];
                 auto ret = pSvgStyleAttributes->getMaskXLink();
-                mbResolvingParent = false;
+                --maResolvingParent[25];
                 return ret;
             }
 
@@ -2868,11 +2870,11 @@ namespace svgio
 
             const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle();
 
-            if (pSvgStyleAttributes && !mbResolvingParent)
+            if (pSvgStyleAttributes && maResolvingParent[26] < nStyleDepthLimit)
             {
-                mbResolvingParent = true;
+                ++maResolvingParent[26];
                 auto ret = pSvgStyleAttributes->getMarkerStartXLink();
-                mbResolvingParent = false;
+                --maResolvingParent[26];
                 return ret;
             }
 
@@ -2903,11 +2905,11 @@ namespace svgio
 
             const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle();
 
-            if (pSvgStyleAttributes && !mbResolvingParent)
+            if (pSvgStyleAttributes && maResolvingParent[27] < nStyleDepthLimit)
             {
-                mbResolvingParent = true;
+                ++maResolvingParent[27];
                 auto ret = pSvgStyleAttributes->getMarkerMidXLink();
-                mbResolvingParent = false;
+                --maResolvingParent[27];
                 return ret;
             }
 
@@ -2938,11 +2940,11 @@ namespace svgio
 
             const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle();
 
-            if (pSvgStyleAttributes && !mbResolvingParent)
+            if (pSvgStyleAttributes && maResolvingParent[28] < nStyleDepthLimit)
             {
-                mbResolvingParent = true;
+                ++maResolvingParent[28];
                 auto ret = pSvgStyleAttributes->getMarkerEndXLink();
-                mbResolvingParent = false;
+                --maResolvingParent[28];
                 return ret;
             }
 
@@ -2971,11 +2973,11 @@ namespace svgio
             {
                 const SvgStyleAttributes* pSvgStyleAttributes = getParentStyle();
 
-                if (pSvgStyleAttributes && !mbResolvingParent)
+                if (pSvgStyleAttributes && maResolvingParent[29] < nStyleDepthLimit)
                 {
-                    mbResolvingParent = true;
+                    ++maResolvingParent[29];
                     const SvgNumber aParentNumber = pSvgStyleAttributes->getBaselineShiftNumber();
-                    mbResolvingParent = false;
+                    --maResolvingParent[29];
 
                     return SvgNumber(
                         aParentNumber.getNumber() * maBaselineShiftNumber.getNumber() * 0.01,


More information about the Libreoffice-commits mailing list