Bug 793612 - Make nsSVGArcConverter robust against zero-sized arc segments. r=longsonr
authorCameron McCormack <cam@mcc.id.au>
Mon, 24 Sep 2012 22:07:41 +1000
changeset 108010 6a18b979c82cde17705497467a3dfd456f34cc6d
parent 108009 e950ed8dc21fffa3198948b30732f9f94a12120f
child 108011 9f0be04eee5fb57e4ab7334e00d0006086f3dbcc
push id82
push usershu@rfrn.org
push dateFri, 05 Oct 2012 13:20:22 +0000
reviewerslongsonr
bugs793612
milestone18.0a1
Bug 793612 - Make nsSVGArcConverter robust against zero-sized arc segments. r=longsonr
content/svg/content/src/nsSVGPathDataParser.cpp
layout/reftests/svg/path-06-ref.svg
layout/reftests/svg/path-06.svg
layout/reftests/svg/reftest.list
--- a/content/svg/content/src/nsSVGPathDataParser.cpp
+++ b/content/svg/content/src/nsSVGPathDataParser.cpp
@@ -850,16 +850,22 @@ CalcVectorAngle(double ux, double uy, do
 nsSVGArcConverter::nsSVGArcConverter(const gfxPoint &from,
                                      const gfxPoint &to,
                                      const gfxPoint &radii,
                                      double angle,
                                      bool largeArcFlag,
                                      bool sweepFlag)
 {
   const double radPerDeg = M_PI/180.0;
+  mSegIndex = 0;
+
+  if (from == to) {
+    mNumSegs = 0;
+    return;
+  }
 
   // Convert to center parameterization as shown in
   // http://www.w3.org/TR/SVG/implnote.html
   mRx = fabs(radii.x);
   mRy = fabs(radii.y);
 
   mSinPhi = sin(angle*radPerDeg);
   mCosPhi = cos(angle*radPerDeg);
@@ -905,17 +911,16 @@ nsSVGArcConverter::nsSVGArcConverter(con
     dtheta += 2.0*M_PI;
 
   // Convert into cubic bezier segments <= 90deg
   mNumSegs = static_cast<int>(ceil(fabs(dtheta/(M_PI/2.0))));
   mDelta = dtheta/mNumSegs;
   mT = 8.0/3.0 * sin(mDelta/4.0) * sin(mDelta/4.0) / sin(mDelta/2.0);
 
   mFrom = from;
-  mSegIndex = 0;
 }
 
 bool
 nsSVGArcConverter::GetNextSegment(gfxPoint *cp1, gfxPoint *cp2, gfxPoint *to)
 {
   if (mSegIndex == mNumSegs) {
     return false;
   }
new file mode 100644
--- /dev/null
+++ b/layout/reftests/svg/path-06-ref.svg
@@ -0,0 +1,13 @@
+<!--
+     Any copyright is dedicated to the Public Domain.
+     http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<svg xmlns="http://www.w3.org/2000/svg">
+
+  <title>Reference for zero-sized path arc handling</title>
+
+  <!-- From https://bugzilla.mozilla.org/show_bug.cgi?id=793612 -->
+
+  <!-- Check that a zero-sized arc segment is ignored. -->
+  <path d="M 100,100 H 200 H 300" stroke="red" stroke-width="3px"/>
+</svg>
new file mode 100644
--- /dev/null
+++ b/layout/reftests/svg/path-06.svg
@@ -0,0 +1,13 @@
+<!--
+     Any copyright is dedicated to the Public Domain.
+     http://creativecommons.org/publicdomain/zero/1.0/
+-->
+<svg xmlns="http://www.w3.org/2000/svg">
+
+  <title>Testcase for zero-sized path arc handling</title>
+
+  <!-- From https://bugzilla.mozilla.org/show_bug.cgi?id=793612 -->
+
+  <!-- Check that a zero-sized arc segment is ignored. -->
+  <path d="M 100,100 H 200 A 200,100 0 0 0 200,100 H 300" stroke="red" stroke-width="3px"/>
+</svg>
--- a/layout/reftests/svg/reftest.list
+++ b/layout/reftests/svg/reftest.list
@@ -195,16 +195,17 @@ random-if(gtk2Widget) == objectBoundingB
 == opacity-and-gradient-02.svg opacity-and-gradient-02-ref.svg
 == opacity-and-pattern-01.svg pass.svg
 == outer-svg-border-and-padding-01.svg outer-svg-border-and-padding-01-ref.svg 
 == path-01.svg path-01-ref.svg
 == path-02.svg pass.svg
 == path-03.svg pass.svg
 == path-04.svg pass.svg
 == path-05.svg pass.svg
+== path-06.svg path-06-ref.svg
 == pathLength-01.svg pass.svg
 == pathLength-02.svg pass.svg
 == pattern-invalid-01.svg pattern-invalid-01-ref.svg
 == pattern-live-01a.svg pattern-live-01-ref.svg
 == pattern-live-01b.svg pattern-live-01-ref.svg
 == pattern-live-01c.svg pattern-live-01-ref.svg
 == pattern-scale-01a.svg pattern-scale-01-ref.svg
 == pattern-scale-01b.svg pattern-scale-01-ref.svg