aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests
diff options
context:
space:
mode:
authorGravatar Mike Reed <reed@google.com>2017-01-03 13:58:21 -0500
committerGravatar Skia Commit-Bot <skia-commit-bot@chromium.org>2017-01-03 19:31:26 +0000
commite3374d68932ce5bd1e6a50b05a6764a543c00c39 (patch)
tree3c972d188c1435fe796304b6c693062f46d551e9 /tests
parentb0b625b79605ab0a18aa038f3f87e88da2441c16 (diff)
validate deserialized path verbs
BUG=676755 Change-Id: Ie9bd70d3a130c53737756587f73c9dce4a6bcb6d Reviewed-on: https://skia-review.googlesource.com/6529 Commit-Queue: Mike Reed <reed@google.com> Reviewed-by: Cary Clark <caryclark@google.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/PathTest.cpp65
1 files changed, 65 insertions, 0 deletions
diff --git a/tests/PathTest.cpp b/tests/PathTest.cpp
index 9a44d2932d..2059c36db3 100644
--- a/tests/PathTest.cpp
+++ b/tests/PathTest.cpp
@@ -2532,6 +2532,69 @@ static void write_and_read_back(skiatest::Reporter* reporter,
REPORTER_ASSERT(reporter, origBounds == readBackBounds);
}
+static void test_corrupt_flattening(skiatest::Reporter* reporter) {
+ SkPath path;
+ path.moveTo(1, 2);
+ path.lineTo(1, 2);
+ path.quadTo(1, 2, 3, 4);
+ path.conicTo(1, 2, 3, 4, 0.5f);
+ path.cubicTo(1, 2, 3, 4, 5, 6);
+ uint8_t buffer[1024];
+ SkDEBUGCODE(size_t size =) path.writeToMemory(buffer);
+ SkASSERT(size <= sizeof(buffer));
+
+ // find where the counts and verbs are stored : from the impl in SkPathRef.cpp
+ int32_t* vCount = (int32_t*)&buffer[16];
+ SkASSERT(*vCount == 5);
+ int32_t* pCount = (int32_t*)&buffer[20];
+ SkASSERT(*pCount == 9);
+ int32_t* cCount = (int32_t*)&buffer[24];
+ SkASSERT(*cCount == 1);
+ uint8_t* verbs = &buffer[28];
+
+ REPORTER_ASSERT(reporter, path.readFromMemory(buffer, sizeof(buffer)));
+
+ // check that we detect under/over-flow of counts
+
+ *vCount += 1;
+ REPORTER_ASSERT(reporter, !path.readFromMemory(buffer, sizeof(buffer)));
+ *vCount -= 1; // restore
+
+ *pCount += 1;
+ REPORTER_ASSERT(reporter, !path.readFromMemory(buffer, sizeof(buffer)));
+ *pCount -= 2;
+ REPORTER_ASSERT(reporter, !path.readFromMemory(buffer, sizeof(buffer)));
+ *pCount += 1; // restore
+
+ *cCount += 1;
+ REPORTER_ASSERT(reporter, !path.readFromMemory(buffer, sizeof(buffer)));
+ *cCount -= 2;
+ REPORTER_ASSERT(reporter, !path.readFromMemory(buffer, sizeof(buffer)));
+ *cCount += 1; // restore
+
+ // Check that we detect when the verbs indicate more or fewer pts/conics
+
+ uint8_t save = verbs[0];
+ SkASSERT(save == SkPath::kCubic_Verb);
+ verbs[0] = SkPath::kQuad_Verb;
+ REPORTER_ASSERT(reporter, !path.readFromMemory(buffer, sizeof(buffer)));
+ verbs[0] = save;
+
+ save = verbs[1];
+ SkASSERT(save == SkPath::kConic_Verb);
+ verbs[1] = SkPath::kQuad_Verb;
+ REPORTER_ASSERT(reporter, !path.readFromMemory(buffer, sizeof(buffer)));
+ verbs[1] = SkPath::kCubic_Verb;
+ REPORTER_ASSERT(reporter, !path.readFromMemory(buffer, sizeof(buffer)));
+ verbs[1] = save;
+
+ // Check that we detect invalid verbs
+ save = verbs[1];
+ verbs[1] = 17;
+ REPORTER_ASSERT(reporter, !path.readFromMemory(buffer, sizeof(buffer)));
+ verbs[1] = save;
+}
+
static void test_flattening(skiatest::Reporter* reporter) {
SkPath p;
@@ -2580,6 +2643,8 @@ static void test_flattening(skiatest::Reporter* reporter) {
write_and_read_back(reporter, oval);
}
+
+ test_corrupt_flattening(reporter);
}
static void test_transform(skiatest::Reporter* reporter) {