Fix a crash in SkParsePath::FromSVGString

BUG=skia:3491

Review URL: https://codereview.chromium.org/1515193002
diff --git a/src/utils/SkParsePath.cpp b/src/utils/SkParsePath.cpp
index 3fecb46..3eb9e1e 100644
--- a/src/utils/SkParsePath.cpp
+++ b/src/utils/SkParsePath.cpp
@@ -77,6 +77,10 @@
     char previousOp = '\0';
     bool relative = false;
     for (;;) {
+        if (!data) {
+            // Truncated data
+            return false;
+        }
         data = skip_ws(data);
         if (data[0] == '\0') {
             break;
diff --git a/tests/ParsePathTest.cpp b/tests/ParsePathTest.cpp
index d2059d6..561eed0 100644
--- a/tests/ParsePathTest.cpp
+++ b/tests/ParsePathTest.cpp
@@ -63,3 +63,11 @@
     p.addRoundRect(r, 4, 4.5f);
     test_to_from(reporter, p);
 }
+
+DEF_TEST(ParsePath_invalid, r) {
+    SkPath path;
+    // This is an invalid SVG string, but the test verifies that we do not
+    // crash.
+    bool success = SkParsePath::FromSVGString("M 5", &path);
+    REPORTER_ASSERT(r, !success);
+}