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/SkCanvas.h" 10 #include "include/core/SkData.h" 11 #include "include/core/SkPaint.h" 12 #include "include/core/SkSurface.h" 13 #include "src/core/SkRegionPriv.h" 14 FuzzRegionDeserialize(sk_sp<SkData> bytes)15bool FuzzRegionDeserialize(sk_sp<SkData> bytes) { 16 SkRegion region; 17 if (!region.readFromMemory(bytes->data(), bytes->size())) { 18 return false; 19 } 20 region.computeRegionComplexity(); 21 region.isComplex(); 22 SkRegion r2; 23 if (region == r2) { 24 region.contains(0,0); 25 } else { 26 region.contains(1,1); 27 } 28 auto s = SkSurface::MakeRasterN32Premul(128, 128); 29 if (!s) { 30 // May return nullptr in memory-constrained fuzzing environments 31 return false; 32 } 33 s->getCanvas()->drawRegion(region, SkPaint()); 34 SkDEBUGCODE(SkRegionPriv::Validate(region)); 35 return true; 36 } 37 38 // TODO(kjlubick): remove IS_FUZZING... after https://crrev.com/c/2410304 lands 39 #if defined(SK_BUILD_FOR_LIBFUZZER) || defined(IS_FUZZING_WITH_LIBFUZZER) LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)40extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { 41 if (size > 512) { 42 return 0; 43 } 44 auto bytes = SkData::MakeWithoutCopy(data, size); 45 FuzzRegionDeserialize(bytes); 46 return 0; 47 } 48 #endif 49