blob: 8a4d43be0469c7a28cd8ed45f1a68c327c79496a [file] [log] [blame]
Kevin Lubick2541edf2018-01-11 10:27:14 -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
Mike Kleinc0bd9f92019-04-23 12:05:21 -05008#include "fuzz/Fuzz.h"
9#include "fuzz/FuzzCommon.h"
10#include "include/core/SkData.h"
11#include "include/core/SkPath.h"
12#include "include/core/SkRegion.h"
Kevin Lubick2541edf2018-01-11 10:27:14 -050013
14
15void FuzzRegionSetPath(Fuzz* fuzz) {
16 SkPath p;
Mike Klein7ffa40c2018-09-25 12:16:53 -040017 FuzzNicePath(fuzz, &p, 1000);
Kevin Lubick2541edf2018-01-11 10:27:14 -050018 SkRegion r1;
19 bool initR1;
20 fuzz->next(&initR1);
21 if (initR1) {
22 fuzz->next(&r1);
23 }
24 SkRegion r2;
25 fuzz->next(&r2);
26
27 r1.setPath(p, r2);
28
29 // Do some follow on computations to make sure region is well-formed.
30 r1.computeRegionComplexity();
31 r1.isComplex();
32 if (r1 == r2) {
33 r1.contains(0,0);
34 } else {
35 r1.contains(1,1);
36 }
37}
38
Kevin Lubick493f89e2020-09-14 08:37:35 -040039#if defined(SK_BUILD_FOR_LIBFUZZER)
Kevin Lubick2541edf2018-01-11 10:27:14 -050040extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
Zepeng Hu5b35f212020-06-14 19:03:34 +000041 if (size > 512) {
42 return 0;
43 }
Kevin Lubick2541edf2018-01-11 10:27:14 -050044 sk_sp<SkData> bytes(SkData::MakeWithoutCopy(data, size));
45 Fuzz fuzz(bytes);
46 FuzzRegionSetPath(&fuzz);
47 return 0;
48}
49#endif