diff options
author | scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-01-09 22:02:58 +0000 |
---|---|---|
committer | scroggo@google.com <scroggo@google.com@2bbb7eff-a529-9590-31e7-b0007b416f81> | 2013-01-09 22:02:58 +0000 |
commit | e490420efc931db8d2c8f397ddf704aab980295d (patch) | |
tree | c41533c4643114e662cdc5c705d54847a06a169a /tests/StreamTest.cpp | |
parent | 74dda9018e8bdd650698e763404f19144c6d0a42 (diff) |
Ensure that SkMemoryStream does not crash dereferencing fData.
SkMemoryStream attempts to dereference fData in multiple places.
Instead of allowing it to be NULL, resulting in a crash, set it
to SkData::NewEmpty().
Add a test for SkStream that will crash when its SkData is set to NULL.
Review URL: https://codereview.appspot.com/7061059
git-svn-id: http://skia.googlecode.com/svn/trunk@7111 2bbb7eff-a529-9590-31e7-b0007b416f81
Diffstat (limited to 'tests/StreamTest.cpp')
-rw-r--r-- | tests/StreamTest.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/tests/StreamTest.cpp b/tests/StreamTest.cpp index b5e3cd98b8..ed51aa7baf 100644 --- a/tests/StreamTest.cpp +++ b/tests/StreamTest.cpp @@ -130,10 +130,29 @@ static void TestPackedUInt(skiatest::Reporter* reporter) { } } +// Test that setting an SkMemoryStream to a NULL data does not result in a crash when calling +// methods that access fData. +static void TestDereferencingData(SkMemoryStream* memStream) { + memStream->read(NULL, 0); + memStream->getMemoryBase(); + SkAutoDataUnref data(memStream->copyToData()); +} + +static void TestNullData() { + SkData* nullData = NULL; + SkMemoryStream memStream(nullData); + TestDereferencingData(&memStream); + + memStream.setData(nullData); + TestDereferencingData(&memStream); + +} + static void TestStreams(skiatest::Reporter* reporter) { TestRStream(reporter); TestWStream(reporter); TestPackedUInt(reporter); + TestNullData(); } #include "TestClassDef.h" |