1 /*
2 * Copyright 2018 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8
9 #include "include/core/SkBitmap.h"
10 #include "include/core/SkCanvas.h"
11 #include "include/core/SkImage.h"
12 #include "include/core/SkImageFilter.h"
13 #include "include/core/SkPaint.h"
14 #include "tools/fonts/FontToolUtils.h"
15
FuzzImageFilterDeserialize(const uint8_t * data,size_t size)16 void FuzzImageFilterDeserialize(const uint8_t *data, size_t size) {
17 const int BitmapSize = 24;
18 SkBitmap bitmap;
19 bitmap.allocN32Pixels(BitmapSize, BitmapSize);
20 SkCanvas canvas(bitmap);
21 canvas.clear(0x00000000);
22
23 auto flattenable = SkImageFilter::Deserialize(data, size);
24
25 if (flattenable != nullptr) {
26 // Let's see if using the filters can cause any trouble...
27 SkPaint paint;
28 paint.setImageFilter(flattenable);
29 canvas.save();
30 canvas.clipIRect(bitmap.bounds());
31
32 // This call shouldn't crash or cause ASAN to flag any memory issues
33 // If nothing bad happens within this call, everything is fine
34 canvas.drawImage(bitmap.asImage(), 0, 0, SkSamplingOptions(), &paint);
35
36 canvas.restore();
37 }
38 }
39
40 #if defined(SK_BUILD_FOR_LIBFUZZER)
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)41 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
42 if (size > 10024) {
43 return 0;
44 }
45 ToolUtils::UsePortableFontMgr();
46 FuzzImageFilterDeserialize(data, size);
47 return 0;
48 }
49 #endif
50