blob: 0584d31e5be29135a2f6baee9a7ed09a68a85a3a [file] [log] [blame]
Kevin Lubickf034d112018-02-08 14:31:24 -05001/*
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#include "SkCanvas.h"
9#include "SkPaint.h"
10#include "SkPath.h"
11#include "SkReadBuffer.h"
12#include "SkSurface.h"
13
14void FuzzPathDeserialize(SkReadBuffer& buf) {
15 SkPath path;
16 buf.readPath(&path);
17 if (!buf.isValid()) {
18 return;
19 }
20
21 auto s = SkSurface::MakeRasterN32Premul(128, 128);
22 if (!s) {
23 // May return nullptr in memory-constrained fuzzing environments
24 return;
25 }
26 s->getCanvas()->drawPath(path, SkPaint());
27}
28
29#if defined(IS_FUZZING_WITH_LIBFUZZER)
30extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
Kevin Lubick37c0f712018-02-22 15:49:31 -050031 if (size < 4) {
32 return 0;
33 }
34 uint32_t packed;
35 memcpy(&packed, data, 4);
36 unsigned version = packed & 0xFF;
37 if (version != 4) {
38 // Chrome only will produce version 4, so guide the fuzzer to
39 // only focus on those branches.
40 return 0;
41 }
Kevin Lubickf034d112018-02-08 14:31:24 -050042 SkReadBuffer buf(data, size);
43 FuzzPathDeserialize(buf);
44 return 0;
45}
46#endif