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

Unified Diff: samplecode/SampleFilterFuzz.cpp

Issue 44573002: Enabling validation code in serialization and adding serialization to fuzzer (Closed) Base URL: https://skia.googlecode.com/svn/trunk
Patch Set: Fixed SkValidatingReadBuffer's constructor Created 7 years, 2 months 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 | « include/core/SkFlattenableSerialization.h ('k') | src/core/SkFlattenableSerialization.cpp » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: samplecode/SampleFilterFuzz.cpp
diff --git a/samplecode/SampleFilterFuzz.cpp b/samplecode/SampleFilterFuzz.cpp
index 17e8306f69bb0fc23169c450dca1ac988426332e..c04292dadf633fbc50bd599c5e4a4fc3a392c9f6 100644
--- a/samplecode/SampleFilterFuzz.cpp
+++ b/samplecode/SampleFilterFuzz.cpp
@@ -1,4 +1,3 @@
-
/*
* Copyright 2013 Google Inc.
*
@@ -7,13 +6,14 @@
*/
#include "SampleCode.h"
#include "SkBicubicImageFilter.h"
+#include "SkBitmapDevice.h"
#include "SkBitmapSource.h"
#include "SkBlurImageFilter.h"
#include "SkCanvas.h"
#include "SkColorFilter.h"
#include "SkColorFilterImageFilter.h"
#include "SkComposeImageFilter.h"
-#include "SkBitmapDevice.h"
+#include "SkData.h"
#include "SkDisplacementMapEffect.h"
#include "SkDropShadowImageFilter.h"
#include "SkFlattenableSerialization.h"
@@ -262,6 +262,25 @@ static SkImageFilter* make_image_filter(bool canBeNull = true) {
return (filter || canBeNull) ? filter : make_image_filter(canBeNull);
}
+static SkImageFilter* make_serialized_image_filter() {
+ SkAutoTUnref<SkImageFilter> filter(make_image_filter(false));
+ SkAutoTUnref<SkData> data(SkValidatingSerializeFlattenable(filter));
+ const unsigned char* ptr = static_cast<const unsigned char*>(data->data());
+ size_t len = data->size();
+#ifdef SK_ADD_RANDOM_BIT_FLIPS
+ unsigned char* p = const_cast<unsigned char*>(ptr);
+ for (size_t i = 0; i < len; ++i, ++p) {
+ if ((R(1000) == 1)) { // 0.1% of the time, flip a bit
+ *p ^= (1 << R(8));
+ }
+ }
+#endif // SK_ADD_RANDOM_BIT_FLIPS
+ SkFlattenable* flattenable = SkValidatingDeserializeFlattenable(ptr, len,
+ SkImageFilter::GetFlattenableType());
+ SkASSERT(NULL != flattenable);
+ return static_cast<SkImageFilter*>(flattenable);
+}
+
static void drawClippedBitmap(SkCanvas* canvas, int x, int y, const SkPaint& paint) {
canvas->save();
canvas->clipRect(SkRect::MakeXYWH(SkIntToScalar(x), SkIntToScalar(y),
@@ -272,7 +291,7 @@ static void drawClippedBitmap(SkCanvas* canvas, int x, int y, const SkPaint& pai
static void do_fuzz(SkCanvas* canvas) {
SkPaint paint;
- paint.setImageFilter(make_image_filter());
+ paint.setImageFilter(make_serialized_image_filter())->unref();
drawClippedBitmap(canvas, 0, 0, paint);
}
« no previous file with comments | « include/core/SkFlattenableSerialization.h ('k') | src/core/SkFlattenableSerialization.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698