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