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 #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" 13 14 FuzzRegionSetPath(Fuzz * fuzz)15void FuzzRegionSetPath(Fuzz* fuzz) { 16 SkPath p; 17 FuzzNicePath(fuzz, &p, 1000); 18 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 39 // TODO(kjlubick): remove IS_FUZZING... after https://crrev.com/c/2410304 lands 40 #if defined(SK_BUILD_FOR_LIBFUZZER) || defined(IS_FUZZING_WITH_LIBFUZZER) LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)41extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { 42 if (size > 512) { 43 return 0; 44 } 45 sk_sp<SkData> bytes(SkData::MakeWithoutCopy(data, size)); 46 Fuzz fuzz(bytes); 47 FuzzRegionSetPath(&fuzz); 48 return 0; 49 } 50 #endif 51