Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1422)

Unified Diff: skia/tools/filter_fuzz_stub/filter_fuzz_stub.cc

Issue 67173009: Adding new fuzzer deserialization test code (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added logging.h Created 7 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « skia/skia.gyp ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: skia/tools/filter_fuzz_stub/filter_fuzz_stub.cc
diff --git a/skia/tools/filter_fuzz_stub/filter_fuzz_stub.cc b/skia/tools/filter_fuzz_stub/filter_fuzz_stub.cc
new file mode 100644
index 0000000000000000000000000000000000000000..6da11369f3ca5ca0bc3c0dc5503233e910c56164
--- /dev/null
+++ b/skia/tools/filter_fuzz_stub/filter_fuzz_stub.cc
@@ -0,0 +1,93 @@
+// Copyright (c) 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;
+}
+
« no previous file with comments | « skia/skia.gyp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698