Restrict radial step count

Bug: skia:8164
Change-Id: I180f3c097b76f89ce57b780eaf28fb3db2759831
Reviewed-on: https://skia-review.googlesource.com/142895
Commit-Queue: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Ben Wagner <bungeman@google.com>
Auto-Submit: Jim Van Verth <jvanverth@google.com>
Reviewed-by: Ben Wagner <bungeman@google.com>
diff --git a/src/utils/SkPolyUtils.cpp b/src/utils/SkPolyUtils.cpp
index 0d1b71c..8a4bf49 100644
--- a/src/utils/SkPolyUtils.cpp
+++ b/src/utils/SkPolyUtils.cpp
@@ -486,7 +486,13 @@
     }
     SkScalar theta = SkScalarATan2(rSin, rCos);
 
-    int steps = SkScalarRoundToInt(SkScalarAbs(r*theta*kRecipPixelsPerArcSegment));
+    SkScalar floatSteps = SkScalarAbs(r*theta*kRecipPixelsPerArcSegment);
+    // limit the number of steps to at most max uint16_t (that's all we can index)
+    // knock one value off the top to account for rounding
+    if (floatSteps >= (1 << 16)-1) {
+        return false;
+    }
+    int steps = SkScalarRoundToInt(floatSteps);
 
     SkScalar dTheta = steps > 0 ? theta / steps : 0;
     *rotSin = SkScalarSinCos(dTheta, rotCos);