summaryrefslogtreecommitdiff
path: root/libs/hwui/PathParser.cpp
diff options
context:
space:
mode:
authorDoris Liu <tianliu@google.com>2016-04-07 15:03:11 -0700
committerDoris Liu <tianliu@google.com>2016-04-08 18:01:54 +0000
commit0a1a5167be26d363d4e27bdc7b816f425b7b4e66 (patch)
tree00758e4ff0d4c259c926776319cf097ab7c09d5f /libs/hwui/PathParser.cpp
parentb6e1dafe78b2875ebe1837508e28c8dce2693b19 (diff)
Improve error logging for parsing failures
Bug: 27043594 Change-Id: I901b65f734c49444a78e0714e007e15e2340ab9d
Diffstat (limited to 'libs/hwui/PathParser.cpp')
-rw-r--r--libs/hwui/PathParser.cpp22
1 files changed, 20 insertions, 2 deletions
diff --git a/libs/hwui/PathParser.cpp b/libs/hwui/PathParser.cpp
index 4e9ac9c7f723..7e85333ef36b 100644
--- a/libs/hwui/PathParser.cpp
+++ b/libs/hwui/PathParser.cpp
@@ -156,6 +156,12 @@ static void getFloats(std::vector<float>* outPoints, PathParser::ParseResult* re
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 @@ void PathParser::getPathDataFromString(PathData* data, ParseResult* result,
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 @@ void PathParser::getPathDataFromString(PathData* data, ParseResult* result,
}
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 @@ void PathParser::parseStringForSkPath(SkPath* skPath, ParseResult* result, const
// 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);