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

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: 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
Index: samplecode/SampleFilterFuzz.cpp
diff --git a/samplecode/SampleFilterFuzz.cpp b/samplecode/SampleFilterFuzz.cpp
index 17e8306f69bb0fc23169c450dca1ac988426332e..65ddeda9f7b3cef4763b436f59b1d391b8507632 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);
}
+SkImageFilter* make_serialized_image_filter() {
+ SkImageFilter* filter = make_image_filter(false);
mtklein 2013/10/25 16:17:31 Coming new at this, sorry if these are dumb questi
Stephen White 2013/10/25 16:36:21 Oooh, good catch. This probably leaks (Alexis can
sugoi1 2013/10/25 17:15:04 I probably had an initial implementation that gave
+ SkData* data = SkValidatingSerializeFlattenable(filter);
+ unsigned char* ptr = static_cast<unsigned char*>(const_cast<void*>(data->data()));
mtklein 2013/10/25 16:17:31 Seems like you don't need the const_cast until you
sugoi1 2013/10/25 17:15:04 Done.
+ size_t len = data->size();
+#ifdef SK_ADD_RANDOM_BIT_FLIPS
+ unsigned char* p = 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());
drawClippedBitmap(canvas, 0, 0, paint);
}

Powered by Google App Engine
This is Rietveld 408576698