1 // Copyright 2016 The Chromium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 #include <stddef.h> 6 #include <stdint.h> 7 8 #include "base/logging.h" 9 #include "testing/libfuzzer/fuzzers/skia_path_common.h" 10 #include "third_party/skia/include/core/SkPath.h" 11 #include "third_party/skia/include/pathops/SkPathOps.h" 12 13 struct Environment { EnvironmentEnvironment14 Environment() { 15 // Disable noisy logging as per "libFuzzer in Chrome" documentation: 16 // testing/libfuzzer/getting_started.md#Disable-noisy-error-message-logging. 17 logging::SetMinLogLevel(logging::LOGGING_FATAL); 18 } 19 }; 20 21 Environment* env = new Environment(); 22 23 const int kLastOp = SkPathOp::kReverseDifference_SkPathOp; 24 LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)25extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { 26 SkOpBuilder builder; 27 while (size > 0) { 28 SkPath path; 29 uint8_t op; 30 if (!read<uint8_t>(&data, &size, &op)) 31 break; 32 33 BuildPath(&data, &size, &path, SkPath::Verb::kDone_Verb); 34 builder.add(path, static_cast<SkPathOp>(op % (kLastOp + 1))); 35 } 36 37 SkPath result; 38 builder.resolve(&result); 39 return 0; 40 } 41