Improve error logging for parsing failures
Bug: 27043594
Change-Id: I901b65f734c49444a78e0714e007e15e2340ab9d
diff --git a/libs/hwui/PathParser.cpp b/libs/hwui/PathParser.cpp
index 4e9ac9c..7e85333 100644
--- a/libs/hwui/PathParser.cpp
+++ b/libs/hwui/PathParser.cpp
@@ -156,6 +156,12 @@
return;
}
+bool PathParser::isVerbValid(char verb) {
+ verb = tolower(verb);
+ return verb == 'a' || verb == 'c' || verb == 'h' || verb == 'l' || verb == 'm' || verb == 'q'
+ || verb == 's' || verb == 't' || verb == 'v' || verb == 'z';
+}
+
void PathParser::getPathDataFromString(PathData* data, ParseResult* result,
const char* pathStr, size_t strLen) {
if (pathStr == NULL) {
@@ -171,6 +177,12 @@
end = nextStart(pathStr, strLen, end);
std::vector<float> points;
getFloats(&points, result, pathStr, start, end);
+ if (!isVerbValid(pathStr[start])) {
+ result->failureOccurred = true;
+ result->failureMessage = "Invalid pathData. Failure occurred at position "
+ + std::to_string(start) + " of path: " + pathStr;
+ }
+ // If either verb or points is not valid, return immediately.
if (result->failureOccurred) {
return;
}
@@ -182,10 +194,15 @@
}
if ((end - start) == 1 && start < strLen) {
+ if (!isVerbValid(pathStr[start])) {
+ result->failureOccurred = true;
+ result->failureMessage = "Invalid pathData. Failure occurred at position "
+ + std::to_string(start) + " of path: " + pathStr;
+ return;
+ }
data->verbs.push_back(pathStr[start]);
data->verbSizes.push_back(0);
}
- return;
}
void PathParser::dump(const PathData& data) {
@@ -218,7 +235,8 @@
// Check if there is valid data coming out of parsing the string.
if (pathData.verbs.size() == 0) {
result->failureOccurred = true;
- result->failureMessage = "No verbs found in the string for pathData";
+ result->failureMessage = "No verbs found in the string for pathData: ";
+ result->failureMessage += pathStr;
return;
}
VectorDrawableUtils::verbsToPath(skPath, pathData);
diff --git a/libs/hwui/PathParser.h b/libs/hwui/PathParser.h
index c4bbb74..180a7a3 100644
--- a/libs/hwui/PathParser.h
+++ b/libs/hwui/PathParser.h
@@ -44,6 +44,7 @@
ANDROID_API static void getPathDataFromString(PathData* outData, ParseResult* result,
const char* pathStr, size_t strLength);
static void dump(const PathData& data);
+ static bool isVerbValid(char verb);
};
}; // namespace uirenderer
diff --git a/libs/hwui/tests/unit/VectorDrawableTests.cpp b/libs/hwui/tests/unit/VectorDrawableTests.cpp
index 7208547..796169e 100644
--- a/libs/hwui/tests/unit/VectorDrawableTests.cpp
+++ b/libs/hwui/tests/unit/VectorDrawableTests.cpp
@@ -231,11 +231,12 @@
};
const StringPath sStringPaths[] = {
- {"3e...3", false},
- {"L.M.F.A.O", false},
- {"m 1 1", true},
- {"z", true},
- {"1-2e34567", false}
+ {"3e...3", false}, // Not starting with a verb and ill-formatted float
+ {"L.M.F.A.O", false}, // No floats following verbs
+ {"m 1 1", true}, // Valid path data
+ {"z", true}, // Valid path data
+ {"1-2e34567", false}, // Not starting with a verb and ill-formatted float
+ {"f 4 5", false} // Invalid verb
};