1 /* 2 * Copyright 2024 Google LLC 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 #include "include/core/SkPath.h" 8 #include "include/core/SkString.h" 9 #include "include/private/base/SkAssert.h" 10 #include "include/utils/SkParsePath.h" 11 FuzzParsePath(const uint8_t * data,size_t size)12void FuzzParsePath(const uint8_t* data, size_t size) { 13 SkPath path; 14 // Put into a SkString first because we are not sure if the input 15 // data is null-terminated or not. 16 SkString input((const char*) data, size); 17 if (SkParsePath::FromSVGString(input.c_str(), &path)) { 18 SkString output1 = SkParsePath::ToSVGString(path, SkParsePath::PathEncoding::Absolute); 19 SkString output2 = SkParsePath::ToSVGString(path, SkParsePath::PathEncoding::Relative); 20 // Do something with the output so it is not optimized away. 21 if (output1.startsWith("Impossible") || output2.startsWith("Impossible")) { 22 SK_ABORT("invalid SVG created"); 23 } 24 } 25 } 26 27 #if defined(SK_BUILD_FOR_LIBFUZZER) LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)28extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { 29 if (size > 1000) { 30 return 0; 31 } 32 FuzzParsePath(data, size); 33 return 0; 34 } 35 #endif 36