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);