blob: 0a8c87aef87c08c4bf7b1c2ce51045a800958122 [file] [log] [blame]
Kevin Lubick2416f962018-02-12 08:26:39 -05001/*
Kevin Lubickdb1e5c62018-02-27 08:30:43 -05002 * Copyright 2018 Google, LLC
Kevin Lubick2416f962018-02-12 08:26:39 -05003 *
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#include "SkImage.h"
9#include "SkPaint.h"
10#include "SkCanvas.h"
11#include "SkData.h"
12#include "SkSurface.h"
13
14void FuzzImage(sk_sp<SkData> bytes) {
15 auto img = SkImage::MakeFromEncoded(bytes);
16 if (nullptr == img.get()) {
17 return;
18 }
19
20 auto s = SkSurface::MakeRasterN32Premul(128, 128);
21 if (!s) {
22 // May return nullptr in memory-constrained fuzzing environments
23 return;
24 }
25
26 SkPaint p;
27 s->getCanvas()->drawImage(img, 0, 0, &p);
28
29}
30
31#if defined(IS_FUZZING_WITH_LIBFUZZER)
32extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
33 auto bytes = SkData::MakeWithoutCopy(data, size);
34 FuzzImage(bytes);
35 return 0;
36}
37#endif