Check for valid normals when offsetting

Bug: oss-fuzz:11546
Change-Id: I45cc443bcee240eebfa72fb0bdb19cb43192804f
Reviewed-on: https://skia-review.googlesource.com/c/173422
Reviewed-by: Kevin Lubick <kjlubick@google.com>
Commit-Queue: Jim Van Verth <jvanverth@google.com>
diff --git a/src/utils/SkPolyUtils.cpp b/src/utils/SkPolyUtils.cpp
index b450b9c..7ec4e46 100644
--- a/src/utils/SkPolyUtils.cpp
+++ b/src/utils/SkPolyUtils.cpp
@@ -61,13 +61,16 @@
 }
 
 // Compute difference vector to offset p0-p1 'offset' units in direction specified by 'side'
-void compute_offset_vector(const SkPoint& p0, const SkPoint& p1, SkScalar offset, int side,
+bool compute_offset_vector(const SkPoint& p0, const SkPoint& p1, SkScalar offset, int side,
                            SkPoint* vector) {
     SkASSERT(side == -1 || side == 1);
     // if distances are equal, can just outset by the perpendicular
     SkVector perp = SkVector::Make(p0.fY - p1.fY, p1.fX - p0.fX);
-    perp.setLength(offset*side);
+    if (!perp.setLength(offset*side)) {
+        return false;
+    }
     *vector = perp;
+    return true;
 }
 
 // check interval to see if intersection is in segment
@@ -1160,8 +1163,10 @@
             return false;
         }
         int nextIndex = (currIndex + 1) % inputPolygonSize;
-        compute_offset_vector(inputPolygonVerts[currIndex], inputPolygonVerts[nextIndex],
-                              offset, winding, &normals[currIndex]);
+        if (!compute_offset_vector(inputPolygonVerts[currIndex], inputPolygonVerts[nextIndex],
+                                   offset, winding, &normals[currIndex])) {
+            return false;
+        }
         if (currIndex > 0) {
             // if reflex point, we need to add extra edges
             if (is_reflex_vertex(inputPolygonVerts, winding, offset,