Skip to content

Commit

Permalink
Adding new fuzzer deserialization test code
Browse files Browse the repository at this point in the history
BUG=

Review URL: https://codereview.chromium.org/67173009

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@235846 0039d316-1c4b-4281-b951-d872f2087c98
  • Loading branch information
sugoi@chromium.org committed Nov 18, 2013
1 parent 1c24cf2 commit 6e8e4f8
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 0 deletions.
1 change: 1 addition & 0 deletions build/all.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -608,6 +608,7 @@
['OS!="win"', {
'dependencies': [
'../net/net.gyp:dns_fuzz_stub',
'../skia/skia.gyp:filter_fuzz_stub',
],
}],
['OS=="win" and fastbuild==0 and target_arch=="ia32"', {
Expand Down
11 changes: 11 additions & 0 deletions skia/skia.gyp
Original file line number Diff line number Diff line change
Expand Up @@ -133,5 +133,16 @@
'ext/image_operations_bench.cc',
],
},
{
'target_name': 'filter_fuzz_stub',
'type': 'executable',
'dependencies': [
'../base/base.gyp:base',
'skia.gyp:skia',
],
'sources': [
'tools/filter_fuzz_stub/filter_fuzz_stub.cc',
],
},
],
}
93 changes: 93 additions & 0 deletions skia/tools/filter_fuzz_stub/filter_fuzz_stub.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/file_util.h"
#include "base/logging.h"
#include "third_party/skia/include/core/SkBitmapDevice.h"
#include "third_party/skia/include/core/SkCanvas.h"
#include "third_party/skia/include/core/SkFlattenableSerialization.h"
#include "third_party/skia/include/core/SkImageFilter.h"

namespace {

static const int BitmapSize = 24;

bool ReadTestCase(const char* filename, std::string* ipc_filter_message) {
base::FilePath filepath = base::FilePath::FromUTF8Unsafe(filename);

if (!base::ReadFileToString(filepath, ipc_filter_message)) {
LOG(ERROR) << filename << ": couldn't read file.";
return false;
}

return true;
}

void RunTestCase(std::string& ipc_filter_message, SkBitmap& bitmap,
SkCanvas* canvas) {
// This call shouldn't crash or cause ASAN to flag any memory issues
// If nothing bad happens within this call, everything is fine
SkFlattenable* flattenable = SkValidatingDeserializeFlattenable(
ipc_filter_message.c_str(), ipc_filter_message.size(),
SkImageFilter::GetFlattenableType());

// Adding some info, but the test passed if we got here without any trouble
if (flattenable != NULL) {
LOG(INFO) << "Valid stream detected.";
// Let's see if using the filters can cause any trouble...
SkPaint paint;
paint.setImageFilter(static_cast<SkImageFilter*>(flattenable))->unref();
canvas->save();
canvas->clipRect(SkRect::MakeXYWH(
0, 0, SkIntToScalar(BitmapSize), SkIntToScalar(BitmapSize)));

// This call shouldn't crash or cause ASAN to flag any memory issues
// If nothing bad happens within this call, everything is fine
canvas->drawBitmap(bitmap, 0, 0, &paint);

LOG(INFO) << "Filter DAG rendered successfully";
canvas->restore();
} else {
LOG(INFO) << "Invalid stream detected.";
}
}

bool ReadAndRunTestCase(const char* filename, SkBitmap& bitmap,
SkCanvas* canvas) {
std::string ipc_filter_message;

LOG(INFO) << "Test case: " << filename;

// ReadTestCase will print a useful error message if it fails.
if (!ReadTestCase(filename, &ipc_filter_message))
return false;

RunTestCase(ipc_filter_message, bitmap, canvas);

return true;
}

}

int main(int argc, char** argv) {
int ret = 0;

SkBitmap bitmap;
bitmap.setConfig(SkBitmap::kARGB_8888_Config, BitmapSize, BitmapSize);
bitmap.allocPixels();
SkBitmapDevice device(bitmap);
SkCanvas canvas(&device);
canvas.clear(0x00000000);

for (int i = 1; i < argc; i++)
if (!ReadAndRunTestCase(argv[i], bitmap, &canvas))
ret = 2;

// Cluster-Fuzz likes "#EOF" as the last line of output to help distinguish
// successful runs from crashes.
printf("#EOF\n");

return ret;
}

0 comments on commit 6e8e4f8

Please sign in to comment.