aboutsummaryrefslogtreecommitdiffhomepage
path: root/tests/MatrixTest.cpp
diff options
context:
space:
mode:
authorGravatar sugoi@google.com <sugoi@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-11-04 20:28:23 +0000
committerGravatar sugoi@google.com <sugoi@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81>2013-11-04 20:28:23 +0000
commitb48a59ae81a35642fe715a5cdd6fd758b652bff3 (patch)
tree4f901dda30343d1bf1ec06e97abeb8a3f384ed20 /tests/MatrixTest.cpp
parentac9d306a92e569e85a7611e9db00943b5b551f1e (diff)
Checking structure sizes before reading them from memory to avoid overflowing the buffer's stream.
BUG= R=reed@google.com Committed: https://code.google.com/p/skia/source/detail?r=12114 Review URL: https://codereview.chromium.org/41253002 git-svn-id: http://skia.googlecode.com/svn/trunk@12119 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests/MatrixTest.cpp')
-rw-r--r--tests/MatrixTest.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/tests/MatrixTest.cpp b/tests/MatrixTest.cpp
index 07eacb6f44..e9886941eb 100644
--- a/tests/MatrixTest.cpp
+++ b/tests/MatrixTest.cpp
@@ -112,18 +112,19 @@ static void test_matrix_recttorect(skiatest::Reporter* reporter) {
static void test_flatten(skiatest::Reporter* reporter, const SkMatrix& m) {
// add 100 in case we have a bug, I don't want to kill my stack in the test
- char buffer[SkMatrix::kMaxFlattenSize + 100];
- uint32_t size1 = m.writeToMemory(NULL);
- uint32_t size2 = m.writeToMemory(buffer);
+ static const size_t kBufferSize = SkMatrix::kMaxFlattenSize + 100;
+ char buffer[kBufferSize];
+ size_t size1 = m.writeToMemory(NULL);
+ size_t size2 = m.writeToMemory(buffer);
REPORTER_ASSERT(reporter, size1 == size2);
REPORTER_ASSERT(reporter, size1 <= SkMatrix::kMaxFlattenSize);
SkMatrix m2;
- uint32_t size3 = m2.readFromMemory(buffer);
+ size_t size3 = m2.readFromMemory(buffer, kBufferSize);
REPORTER_ASSERT(reporter, size1 == size3);
REPORTER_ASSERT(reporter, are_equal(reporter, m, m2));
- char buffer2[SkMatrix::kMaxFlattenSize + 100];
+ char buffer2[kBufferSize];
size3 = m2.writeToMemory(buffer2);
REPORTER_ASSERT(reporter, size1 == size3);
REPORTER_ASSERT(reporter, memcmp(buffer, buffer2, size1) == 0);