/src/skia/fuzz/oss_fuzz/FuzzAnimatedImage.cpp
Line | Count | Source (jump to first uncovered line) |
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 "include/android/SkAnimatedImage.h" |
9 | | #include "include/codec/SkAndroidCodec.h" |
10 | | #include "include/core/SkCanvas.h" |
11 | | #include "include/core/SkStream.h" |
12 | | #include "include/core/SkSurface.h" |
13 | | |
14 | 13.8k | bool FuzzAnimatedImage(const uint8_t *data, size_t size) { |
15 | 13.8k | auto codec = SkAndroidCodec::MakeFromStream(SkMemoryStream::MakeDirect(data, size)); |
16 | 13.8k | if (nullptr == codec) { |
17 | 6.05k | return false; |
18 | 6.05k | } |
19 | 7.82k | auto aImg = SkAnimatedImage::Make(std::move(codec)); |
20 | 7.82k | if (nullptr == aImg) { |
21 | 5.42k | return false; |
22 | 5.42k | } |
23 | | |
24 | 2.39k | auto s = SkSurfaces::Raster(SkImageInfo::MakeN32Premul(128, 128)); |
25 | 2.39k | if (!s) { |
26 | | // May return nullptr in memory-constrained fuzzing environments |
27 | 0 | return false; |
28 | 0 | } |
29 | | |
30 | 2.39k | int escape = 0; |
31 | 57.4k | while (!aImg->isFinished() && escape < 100) { |
32 | 55.0k | aImg->draw(s->getCanvas()); |
33 | 55.0k | escape++; |
34 | 55.0k | aImg->decodeNextFrame(); |
35 | 55.0k | } |
36 | 2.39k | return true; |
37 | 2.39k | } |
38 | | |
39 | | #if defined(SK_BUILD_FOR_LIBFUZZER) |
40 | 190k | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
41 | 190k | if (size > 10240) { |
42 | 220 | return 0; |
43 | 220 | } |
44 | 190k | FuzzAnimatedImage(data, size); |
45 | 190k | return 0; |
46 | 190k | } |
47 | | #endif |