Limit iterations when computing convex inset.
In the worst case we should compare each vertex in the polygon
to the others just once, so we should have at worst n^2 iterations.
Bug: skia:8079
Change-Id: Ic22064e86d6eb08d9165b2feb5050701ec8e9639
Reviewed-on: https://skia-review.googlesource.com/135865
Auto-Submit: Jim Van Verth <jvanverth@google.com>
Reviewed-by: Kevin Lubick <kjlubick@google.com>
Commit-Queue: Jim Van Verth <jvanverth@google.com>
Commit-Queue: Kevin Lubick <kjlubick@google.com>
diff --git a/src/utils/SkOffsetPolygon.cpp b/src/utils/SkOffsetPolygon.cpp
index b335a25..81b692f 100755
--- a/src/utils/SkOffsetPolygon.cpp
+++ b/src/utils/SkOffsetPolygon.cpp
@@ -308,7 +308,13 @@
int prevIndex = inputPolygonSize - 1;
int currIndex = 0;
int insetVertexCount = inputPolygonSize;
+ int iterations = 0;
while (prevIndex != currIndex) {
+ ++iterations;
+ if (iterations > inputPolygonSize*inputPolygonSize) {
+ return false;
+ }
+
if (!edgeData[prevIndex].fValid) {
prevIndex = (prevIndex + inputPolygonSize - 1) % inputPolygonSize;
continue;