Checking structure sizes before reading them from memory to avoid overflowing the buffer's stream.
BUG=
R=reed@google.com, mtklein@google.com, senorblanco@chromium.org
Committed: https://code.google.com/p/skia/source/detail?r=12114
Committed: https://code.google.com/p/skia/source/detail?r=12119
Author: sugoi@chromium.org
Review URL: https://codereview.chromium.org/41253002
git-svn-id: http://skia.googlecode.com/svn/trunk@12130 2bbb7eff-a529-9590-31e7-b0007b416f81
diff --git a/tests/MatrixTest.cpp b/tests/MatrixTest.cpp
index 07eacb6..e988694 100644
--- a/tests/MatrixTest.cpp
+++ b/tests/MatrixTest.cpp
@@ -112,18 +112,19 @@
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);