Kevin Lubick | 9eeede2 | 2018-05-03 16:26:10 -0400 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2018 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 | |
| 8 | #include "SkData.h" |
| 9 | #include "Skottie.h" |
| 10 | #include "SkStream.h" |
| 11 | |
| 12 | void FuzzSkottieJSON(sk_sp<SkData> bytes) { |
| 13 | // Always returns nullptr to any resource |
| 14 | class EmptyResourceProvider final : public skottie::ResourceProvider { |
| 15 | public: |
| 16 | std::unique_ptr<SkStream> openStream(const char resource[]) const override { |
| 17 | return nullptr; |
| 18 | } |
| 19 | }; |
| 20 | SkMemoryStream stream(bytes); |
| 21 | EmptyResourceProvider erp; |
| 22 | auto animation = skottie::Animation::Make(&stream, erp); |
| 23 | if (!animation) { |
| 24 | return; |
| 25 | } |
| 26 | animation->animationTick(1337); // A "nothing up my sleeve" number |
| 27 | } |
| 28 | |
| 29 | #if defined(IS_FUZZING_WITH_LIBFUZZER) |
| 30 | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
| 31 | auto bytes = SkData::MakeWithoutCopy(data, size); |
| 32 | FuzzSkottieJSON(bytes); |
| 33 | return 0; |
| 34 | } |
| 35 | #endif |