/src/libwebp/tests/fuzzer/fuzz_utils.h
Line | Count | Source |
1 | | // Copyright 2018-2024 Google LLC |
2 | | // |
3 | | // Licensed under the Apache License, Version 2.0 (the "License"); |
4 | | // you may not use this file except in compliance with the License. |
5 | | // You may obtain a copy of the License at |
6 | | // |
7 | | // http://www.apache.org/licenses/LICENSE-2.0 |
8 | | // |
9 | | // Unless required by applicable law or agreed to in writing, software |
10 | | // distributed under the License is distributed on an "AS IS" BASIS, |
11 | | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
12 | | // See the License for the specific language governing permissions and |
13 | | // limitations under the License. |
14 | | // |
15 | | //////////////////////////////////////////////////////////////////////////////// |
16 | | |
17 | | #ifndef WEBP_TESTS_FUZZER_FUZZ_UTILS_H_ |
18 | | #define WEBP_TESTS_FUZZER_FUZZ_UTILS_H_ |
19 | | |
20 | | #include <cstddef> |
21 | | #include <cstdint> |
22 | | #include <cstdlib> |
23 | | #include <optional> |
24 | | #include <string> |
25 | | #include <string_view> |
26 | | #include <utility> |
27 | | #include <vector> |
28 | | |
29 | | #include "./img_alpha.h" |
30 | | #include "./img_grid.h" |
31 | | #include "./img_peak.h" |
32 | | #include "fuzztest/fuzztest.h" |
33 | | #include "src/dsp/cpu.h" |
34 | | #include "src/webp/encode.h" |
35 | | #include "src/webp/types.h" |
36 | | |
37 | | namespace fuzz_utils { |
38 | | |
39 | | //------------------------------------------------------------------------------ |
40 | | // Arbitrary limits to prevent OOM, timeout, or slow execution. |
41 | | |
42 | | // The decoded image size, and for animations additionally the canvas size. |
43 | | // Enabling some sanitizers slow down runtime significantly. |
44 | | // Use a very low threshold in this case to avoid timeouts. |
45 | | #if defined(__SANITIZE_ADDRESS__) // GCC |
46 | | static const size_t kFuzzPxLimit = 1024 * 1024 / 10; |
47 | | #elif !defined(__has_feature) // Clang |
48 | | static const size_t kFuzzPxLimit = 1024 * 1024; |
49 | | #elif __has_feature(address_sanitizer) || __has_feature(memory_sanitizer) |
50 | | static const size_t kFuzzPxLimit = 1024 * 1024 / 18; |
51 | | #else |
52 | | static const size_t kFuzzPxLimit = 1024 * 1024; |
53 | | #endif |
54 | | |
55 | | // Demuxed or decoded animation frames. |
56 | | static const int kFuzzFrameLimit = 3; |
57 | | |
58 | | // Reads and sums (up to) 128 spread-out bytes. |
59 | 12.6k | static WEBP_INLINE uint8_t FuzzHash(const uint8_t* const data, size_t size) { |
60 | 12.6k | uint8_t value = 0; |
61 | 12.6k | size_t incr = size / 128; |
62 | 12.6k | if (!incr) incr = 1; |
63 | 542k | for (size_t i = 0; i < size; i += incr) value += data[i]; |
64 | 12.6k | return value; |
65 | 12.6k | } Unexecuted instantiation: mux_demux_api_fuzzer.cc:fuzz_utils::FuzzHash(unsigned char const*, unsigned long) Unexecuted instantiation: imageio_fuzzer.cc:fuzz_utils::FuzzHash(unsigned char const*, unsigned long) Unexecuted instantiation: fuzz_utils.cc:fuzz_utils::FuzzHash(unsigned char const*, unsigned long) Unexecuted instantiation: huffman_fuzzer.cc:fuzz_utils::FuzzHash(unsigned char const*, unsigned long) Unexecuted instantiation: enc_fuzzer.cc:fuzz_utils::FuzzHash(unsigned char const*, unsigned long) Unexecuted instantiation: webp_info_fuzzer.cc:fuzz_utils::FuzzHash(unsigned char const*, unsigned long) Unexecuted instantiation: animdecoder_fuzzer.cc:fuzz_utils::FuzzHash(unsigned char const*, unsigned long) Unexecuted instantiation: animation_api_fuzzer.cc:fuzz_utils::FuzzHash(unsigned char const*, unsigned long) Unexecuted instantiation: dec_fuzzer.cc:fuzz_utils::FuzzHash(unsigned char const*, unsigned long) Unexecuted instantiation: enc_dec_fuzzer.cc:fuzz_utils::FuzzHash(unsigned char const*, unsigned long) Unexecuted instantiation: animencoder_fuzzer.cc:fuzz_utils::FuzzHash(unsigned char const*, unsigned long) advanced_api_fuzzer.cc:fuzz_utils::FuzzHash(unsigned char const*, unsigned long) Line | Count | Source | 59 | 7.81k | static WEBP_INLINE uint8_t FuzzHash(const uint8_t* const data, size_t size) { | 60 | 7.81k | uint8_t value = 0; | 61 | 7.81k | size_t incr = size / 128; | 62 | 7.81k | if (!incr) incr = 1; | 63 | 335k | for (size_t i = 0; i < size; i += incr) value += data[i]; | 64 | 7.81k | return value; | 65 | 7.81k | } |
simple_api_fuzzer.cc:fuzz_utils::FuzzHash(unsigned char const*, unsigned long) Line | Count | Source | 59 | 4.87k | static WEBP_INLINE uint8_t FuzzHash(const uint8_t* const data, size_t size) { | 60 | 4.87k | uint8_t value = 0; | 61 | 4.87k | size_t incr = size / 128; | 62 | 4.87k | if (!incr) incr = 1; | 63 | 206k | for (size_t i = 0; i < size; i += incr) value += data[i]; | 64 | 4.87k | return value; | 65 | 4.87k | } |
|
66 | | |
67 | | #ifdef __cplusplus |
68 | | extern "C" VP8CPUInfo VP8GetCPUInfo; |
69 | | #else |
70 | | extern VP8CPUInfo VP8GetCPUInfo; |
71 | | #endif |
72 | | |
73 | | //------------------------------------------------------------------------------ |
74 | | |
75 | | constexpr const uint8_t* kImagesData[] = {kImgAlphaData, kImgGridData, |
76 | | kImgPeakData}; |
77 | | constexpr size_t kNumSourceImages = |
78 | | sizeof(kImagesData) / sizeof(kImagesData[0]); |
79 | | |
80 | | WebPPicture GetSourcePicture(int image_index, bool use_argb); |
81 | | |
82 | 6 | static inline auto ArbitraryWebPConfig() { |
83 | 6 | return fuzztest::Map( |
84 | 6 | [](int lossless, int quality, int method, int image_hint, int segments, |
85 | 6 | int sns_strength, int filter_strength, int filter_sharpness, |
86 | 6 | int filter_type, int autofilter, int alpha_compression, |
87 | 6 | int alpha_filtering, int alpha_quality, int pass, int preprocessing, |
88 | 6 | int partitions, int partition_limit, int emulate_jpeg_size, |
89 | 6 | int thread_level, int low_memory, int near_lossless, int exact, |
90 | 26.2k | int use_delta_palette, int use_sharp_yuv) -> WebPConfig { |
91 | 26.2k | WebPConfig config; |
92 | 26.2k | if (!WebPConfigInit(&config)) abort(); |
93 | 26.2k | config.lossless = lossless; |
94 | 26.2k | config.quality = quality; |
95 | 26.2k | config.method = method; |
96 | 26.2k | config.image_hint = (WebPImageHint)image_hint; |
97 | 26.2k | config.segments = segments; |
98 | 26.2k | config.sns_strength = sns_strength; |
99 | 26.2k | config.filter_strength = filter_strength; |
100 | 26.2k | config.filter_sharpness = filter_sharpness; |
101 | 26.2k | config.filter_type = filter_type; |
102 | 26.2k | config.autofilter = autofilter; |
103 | 26.2k | config.alpha_compression = alpha_compression; |
104 | 26.2k | config.alpha_filtering = alpha_filtering; |
105 | 26.2k | config.alpha_quality = alpha_quality; |
106 | 26.2k | config.pass = pass; |
107 | 26.2k | config.show_compressed = 1; |
108 | 26.2k | config.preprocessing = preprocessing; |
109 | 26.2k | config.partitions = partitions; |
110 | 26.2k | config.partition_limit = 10 * partition_limit; |
111 | 26.2k | config.emulate_jpeg_size = emulate_jpeg_size; |
112 | 26.2k | config.thread_level = thread_level; |
113 | 26.2k | config.low_memory = low_memory; |
114 | 26.2k | config.near_lossless = 20 * near_lossless; |
115 | 26.2k | config.exact = exact; |
116 | 26.2k | config.use_delta_palette = use_delta_palette; |
117 | 26.2k | config.use_sharp_yuv = use_sharp_yuv; |
118 | 26.2k | if (!WebPValidateConfig(&config)) abort(); |
119 | 26.2k | return config; |
120 | 26.2k | }, enc_fuzzer.cc:fuzz_utils::ArbitraryWebPConfig()::{lambda(int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int)#1}::operator()(int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int) const Line | Count | Source | 90 | 9.10k | int use_delta_palette, int use_sharp_yuv) -> WebPConfig { | 91 | 9.10k | WebPConfig config; | 92 | 9.10k | if (!WebPConfigInit(&config)) abort(); | 93 | 9.10k | config.lossless = lossless; | 94 | 9.10k | config.quality = quality; | 95 | 9.10k | config.method = method; | 96 | 9.10k | config.image_hint = (WebPImageHint)image_hint; | 97 | 9.10k | config.segments = segments; | 98 | 9.10k | config.sns_strength = sns_strength; | 99 | 9.10k | config.filter_strength = filter_strength; | 100 | 9.10k | config.filter_sharpness = filter_sharpness; | 101 | 9.10k | config.filter_type = filter_type; | 102 | 9.10k | config.autofilter = autofilter; | 103 | 9.10k | config.alpha_compression = alpha_compression; | 104 | 9.10k | config.alpha_filtering = alpha_filtering; | 105 | 9.10k | config.alpha_quality = alpha_quality; | 106 | 9.10k | config.pass = pass; | 107 | 9.10k | config.show_compressed = 1; | 108 | 9.10k | config.preprocessing = preprocessing; | 109 | 9.10k | config.partitions = partitions; | 110 | 9.10k | config.partition_limit = 10 * partition_limit; | 111 | 9.10k | config.emulate_jpeg_size = emulate_jpeg_size; | 112 | 9.10k | config.thread_level = thread_level; | 113 | 9.10k | config.low_memory = low_memory; | 114 | 9.10k | config.near_lossless = 20 * near_lossless; | 115 | 9.10k | config.exact = exact; | 116 | 9.10k | config.use_delta_palette = use_delta_palette; | 117 | 9.10k | config.use_sharp_yuv = use_sharp_yuv; | 118 | 9.10k | if (!WebPValidateConfig(&config)) abort(); | 119 | 9.10k | return config; | 120 | 9.10k | }, |
enc_dec_fuzzer.cc:fuzz_utils::ArbitraryWebPConfig()::{lambda(int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int)#1}::operator()(int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int) const Line | Count | Source | 90 | 3.98k | int use_delta_palette, int use_sharp_yuv) -> WebPConfig { | 91 | 3.98k | WebPConfig config; | 92 | 3.98k | if (!WebPConfigInit(&config)) abort(); | 93 | 3.98k | config.lossless = lossless; | 94 | 3.98k | config.quality = quality; | 95 | 3.98k | config.method = method; | 96 | 3.98k | config.image_hint = (WebPImageHint)image_hint; | 97 | 3.98k | config.segments = segments; | 98 | 3.98k | config.sns_strength = sns_strength; | 99 | 3.98k | config.filter_strength = filter_strength; | 100 | 3.98k | config.filter_sharpness = filter_sharpness; | 101 | 3.98k | config.filter_type = filter_type; | 102 | 3.98k | config.autofilter = autofilter; | 103 | 3.98k | config.alpha_compression = alpha_compression; | 104 | 3.98k | config.alpha_filtering = alpha_filtering; | 105 | 3.98k | config.alpha_quality = alpha_quality; | 106 | 3.98k | config.pass = pass; | 107 | 3.98k | config.show_compressed = 1; | 108 | 3.98k | config.preprocessing = preprocessing; | 109 | 3.98k | config.partitions = partitions; | 110 | 3.98k | config.partition_limit = 10 * partition_limit; | 111 | 3.98k | config.emulate_jpeg_size = emulate_jpeg_size; | 112 | 3.98k | config.thread_level = thread_level; | 113 | 3.98k | config.low_memory = low_memory; | 114 | 3.98k | config.near_lossless = 20 * near_lossless; | 115 | 3.98k | config.exact = exact; | 116 | 3.98k | config.use_delta_palette = use_delta_palette; | 117 | 3.98k | config.use_sharp_yuv = use_sharp_yuv; | 118 | 3.98k | if (!WebPValidateConfig(&config)) abort(); | 119 | 3.98k | return config; | 120 | 3.98k | }, |
animencoder_fuzzer.cc:fuzz_utils::ArbitraryWebPConfig()::{lambda(int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int)#1}::operator()(int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int, int) const Line | Count | Source | 90 | 13.1k | int use_delta_palette, int use_sharp_yuv) -> WebPConfig { | 91 | 13.1k | WebPConfig config; | 92 | 13.1k | if (!WebPConfigInit(&config)) abort(); | 93 | 13.1k | config.lossless = lossless; | 94 | 13.1k | config.quality = quality; | 95 | 13.1k | config.method = method; | 96 | 13.1k | config.image_hint = (WebPImageHint)image_hint; | 97 | 13.1k | config.segments = segments; | 98 | 13.1k | config.sns_strength = sns_strength; | 99 | 13.1k | config.filter_strength = filter_strength; | 100 | 13.1k | config.filter_sharpness = filter_sharpness; | 101 | 13.1k | config.filter_type = filter_type; | 102 | 13.1k | config.autofilter = autofilter; | 103 | 13.1k | config.alpha_compression = alpha_compression; | 104 | 13.1k | config.alpha_filtering = alpha_filtering; | 105 | 13.1k | config.alpha_quality = alpha_quality; | 106 | 13.1k | config.pass = pass; | 107 | 13.1k | config.show_compressed = 1; | 108 | 13.1k | config.preprocessing = preprocessing; | 109 | 13.1k | config.partitions = partitions; | 110 | 13.1k | config.partition_limit = 10 * partition_limit; | 111 | 13.1k | config.emulate_jpeg_size = emulate_jpeg_size; | 112 | 13.1k | config.thread_level = thread_level; | 113 | 13.1k | config.low_memory = low_memory; | 114 | 13.1k | config.near_lossless = 20 * near_lossless; | 115 | 13.1k | config.exact = exact; | 116 | 13.1k | config.use_delta_palette = use_delta_palette; | 117 | 13.1k | config.use_sharp_yuv = use_sharp_yuv; | 118 | 13.1k | if (!WebPValidateConfig(&config)) abort(); | 119 | 13.1k | return config; | 120 | 13.1k | }, |
|
121 | 6 | /*lossless=*/fuzztest::InRange<int>(0, 1), |
122 | 6 | /*quality=*/fuzztest::InRange<int>(0, 100), |
123 | 6 | /*method=*/fuzztest::InRange<int>(0, 6), |
124 | 6 | /*image_hint=*/fuzztest::InRange<int>(0, WEBP_HINT_LAST - 1), |
125 | 6 | /*segments=*/fuzztest::InRange<int>(1, 4), |
126 | 6 | /*sns_strength=*/fuzztest::InRange<int>(0, 100), |
127 | 6 | /*filter_strength=*/fuzztest::InRange<int>(0, 100), |
128 | 6 | /*filter_sharpness=*/fuzztest::InRange<int>(0, 7), |
129 | 6 | /*filter_type=*/fuzztest::InRange<int>(0, 1), |
130 | 6 | /*autofilter=*/fuzztest::InRange<int>(0, 1), |
131 | 6 | /*alpha_compression=*/fuzztest::InRange<int>(0, 1), |
132 | 6 | /*alpha_filtering=*/fuzztest::InRange<int>(0, 2), |
133 | 6 | /*alpha_quality=*/fuzztest::InRange<int>(0, 100), |
134 | 6 | /*pass=*/fuzztest::InRange<int>(1, 10), |
135 | 6 | /*preprocessing=*/fuzztest::InRange<int>(0, 2), |
136 | 6 | /*partitions=*/fuzztest::InRange<int>(0, 3), |
137 | 6 | /*partition_limit=*/fuzztest::InRange<int>(0, 10), |
138 | 6 | /*emulate_jpeg_size=*/fuzztest::InRange<int>(0, 1), |
139 | 6 | /*thread_level=*/fuzztest::InRange<int>(0, 1), |
140 | 6 | /*low_memory=*/fuzztest::InRange<int>(0, 1), |
141 | 6 | /*near_lossless=*/fuzztest::InRange<int>(0, 5), |
142 | 6 | /*exact=*/fuzztest::InRange<int>(0, 1), |
143 | 6 | /*use_delta_palette=*/fuzztest::InRange<int>(0, 1), |
144 | 6 | /*use_sharp_yuv=*/fuzztest::InRange<int>(0, 1)); |
145 | 6 | } Unexecuted instantiation: mux_demux_api_fuzzer.cc:fuzz_utils::ArbitraryWebPConfig() Unexecuted instantiation: imageio_fuzzer.cc:fuzz_utils::ArbitraryWebPConfig() Unexecuted instantiation: fuzz_utils.cc:fuzz_utils::ArbitraryWebPConfig() Unexecuted instantiation: huffman_fuzzer.cc:fuzz_utils::ArbitraryWebPConfig() enc_fuzzer.cc:fuzz_utils::ArbitraryWebPConfig() Line | Count | Source | 82 | 2 | static inline auto ArbitraryWebPConfig() { | 83 | 2 | return fuzztest::Map( | 84 | 2 | [](int lossless, int quality, int method, int image_hint, int segments, | 85 | 2 | int sns_strength, int filter_strength, int filter_sharpness, | 86 | 2 | int filter_type, int autofilter, int alpha_compression, | 87 | 2 | int alpha_filtering, int alpha_quality, int pass, int preprocessing, | 88 | 2 | int partitions, int partition_limit, int emulate_jpeg_size, | 89 | 2 | int thread_level, int low_memory, int near_lossless, int exact, | 90 | 2 | int use_delta_palette, int use_sharp_yuv) -> WebPConfig { | 91 | 2 | WebPConfig config; | 92 | 2 | if (!WebPConfigInit(&config)) abort(); | 93 | 2 | config.lossless = lossless; | 94 | 2 | config.quality = quality; | 95 | 2 | config.method = method; | 96 | 2 | config.image_hint = (WebPImageHint)image_hint; | 97 | 2 | config.segments = segments; | 98 | 2 | config.sns_strength = sns_strength; | 99 | 2 | config.filter_strength = filter_strength; | 100 | 2 | config.filter_sharpness = filter_sharpness; | 101 | 2 | config.filter_type = filter_type; | 102 | 2 | config.autofilter = autofilter; | 103 | 2 | config.alpha_compression = alpha_compression; | 104 | 2 | config.alpha_filtering = alpha_filtering; | 105 | 2 | config.alpha_quality = alpha_quality; | 106 | 2 | config.pass = pass; | 107 | 2 | config.show_compressed = 1; | 108 | 2 | config.preprocessing = preprocessing; | 109 | 2 | config.partitions = partitions; | 110 | 2 | config.partition_limit = 10 * partition_limit; | 111 | 2 | config.emulate_jpeg_size = emulate_jpeg_size; | 112 | 2 | config.thread_level = thread_level; | 113 | 2 | config.low_memory = low_memory; | 114 | 2 | config.near_lossless = 20 * near_lossless; | 115 | 2 | config.exact = exact; | 116 | 2 | config.use_delta_palette = use_delta_palette; | 117 | 2 | config.use_sharp_yuv = use_sharp_yuv; | 118 | 2 | if (!WebPValidateConfig(&config)) abort(); | 119 | 2 | return config; | 120 | 2 | }, | 121 | 2 | /*lossless=*/fuzztest::InRange<int>(0, 1), | 122 | 2 | /*quality=*/fuzztest::InRange<int>(0, 100), | 123 | 2 | /*method=*/fuzztest::InRange<int>(0, 6), | 124 | 2 | /*image_hint=*/fuzztest::InRange<int>(0, WEBP_HINT_LAST - 1), | 125 | 2 | /*segments=*/fuzztest::InRange<int>(1, 4), | 126 | 2 | /*sns_strength=*/fuzztest::InRange<int>(0, 100), | 127 | 2 | /*filter_strength=*/fuzztest::InRange<int>(0, 100), | 128 | 2 | /*filter_sharpness=*/fuzztest::InRange<int>(0, 7), | 129 | 2 | /*filter_type=*/fuzztest::InRange<int>(0, 1), | 130 | 2 | /*autofilter=*/fuzztest::InRange<int>(0, 1), | 131 | 2 | /*alpha_compression=*/fuzztest::InRange<int>(0, 1), | 132 | 2 | /*alpha_filtering=*/fuzztest::InRange<int>(0, 2), | 133 | 2 | /*alpha_quality=*/fuzztest::InRange<int>(0, 100), | 134 | 2 | /*pass=*/fuzztest::InRange<int>(1, 10), | 135 | 2 | /*preprocessing=*/fuzztest::InRange<int>(0, 2), | 136 | 2 | /*partitions=*/fuzztest::InRange<int>(0, 3), | 137 | 2 | /*partition_limit=*/fuzztest::InRange<int>(0, 10), | 138 | 2 | /*emulate_jpeg_size=*/fuzztest::InRange<int>(0, 1), | 139 | 2 | /*thread_level=*/fuzztest::InRange<int>(0, 1), | 140 | 2 | /*low_memory=*/fuzztest::InRange<int>(0, 1), | 141 | 2 | /*near_lossless=*/fuzztest::InRange<int>(0, 5), | 142 | 2 | /*exact=*/fuzztest::InRange<int>(0, 1), | 143 | 2 | /*use_delta_palette=*/fuzztest::InRange<int>(0, 1), | 144 | 2 | /*use_sharp_yuv=*/fuzztest::InRange<int>(0, 1)); | 145 | 2 | } |
Unexecuted instantiation: webp_info_fuzzer.cc:fuzz_utils::ArbitraryWebPConfig() Unexecuted instantiation: animdecoder_fuzzer.cc:fuzz_utils::ArbitraryWebPConfig() Unexecuted instantiation: animation_api_fuzzer.cc:fuzz_utils::ArbitraryWebPConfig() Unexecuted instantiation: dec_fuzzer.cc:fuzz_utils::ArbitraryWebPConfig() enc_dec_fuzzer.cc:fuzz_utils::ArbitraryWebPConfig() Line | Count | Source | 82 | 2 | static inline auto ArbitraryWebPConfig() { | 83 | 2 | return fuzztest::Map( | 84 | 2 | [](int lossless, int quality, int method, int image_hint, int segments, | 85 | 2 | int sns_strength, int filter_strength, int filter_sharpness, | 86 | 2 | int filter_type, int autofilter, int alpha_compression, | 87 | 2 | int alpha_filtering, int alpha_quality, int pass, int preprocessing, | 88 | 2 | int partitions, int partition_limit, int emulate_jpeg_size, | 89 | 2 | int thread_level, int low_memory, int near_lossless, int exact, | 90 | 2 | int use_delta_palette, int use_sharp_yuv) -> WebPConfig { | 91 | 2 | WebPConfig config; | 92 | 2 | if (!WebPConfigInit(&config)) abort(); | 93 | 2 | config.lossless = lossless; | 94 | 2 | config.quality = quality; | 95 | 2 | config.method = method; | 96 | 2 | config.image_hint = (WebPImageHint)image_hint; | 97 | 2 | config.segments = segments; | 98 | 2 | config.sns_strength = sns_strength; | 99 | 2 | config.filter_strength = filter_strength; | 100 | 2 | config.filter_sharpness = filter_sharpness; | 101 | 2 | config.filter_type = filter_type; | 102 | 2 | config.autofilter = autofilter; | 103 | 2 | config.alpha_compression = alpha_compression; | 104 | 2 | config.alpha_filtering = alpha_filtering; | 105 | 2 | config.alpha_quality = alpha_quality; | 106 | 2 | config.pass = pass; | 107 | 2 | config.show_compressed = 1; | 108 | 2 | config.preprocessing = preprocessing; | 109 | 2 | config.partitions = partitions; | 110 | 2 | config.partition_limit = 10 * partition_limit; | 111 | 2 | config.emulate_jpeg_size = emulate_jpeg_size; | 112 | 2 | config.thread_level = thread_level; | 113 | 2 | config.low_memory = low_memory; | 114 | 2 | config.near_lossless = 20 * near_lossless; | 115 | 2 | config.exact = exact; | 116 | 2 | config.use_delta_palette = use_delta_palette; | 117 | 2 | config.use_sharp_yuv = use_sharp_yuv; | 118 | 2 | if (!WebPValidateConfig(&config)) abort(); | 119 | 2 | return config; | 120 | 2 | }, | 121 | 2 | /*lossless=*/fuzztest::InRange<int>(0, 1), | 122 | 2 | /*quality=*/fuzztest::InRange<int>(0, 100), | 123 | 2 | /*method=*/fuzztest::InRange<int>(0, 6), | 124 | 2 | /*image_hint=*/fuzztest::InRange<int>(0, WEBP_HINT_LAST - 1), | 125 | 2 | /*segments=*/fuzztest::InRange<int>(1, 4), | 126 | 2 | /*sns_strength=*/fuzztest::InRange<int>(0, 100), | 127 | 2 | /*filter_strength=*/fuzztest::InRange<int>(0, 100), | 128 | 2 | /*filter_sharpness=*/fuzztest::InRange<int>(0, 7), | 129 | 2 | /*filter_type=*/fuzztest::InRange<int>(0, 1), | 130 | 2 | /*autofilter=*/fuzztest::InRange<int>(0, 1), | 131 | 2 | /*alpha_compression=*/fuzztest::InRange<int>(0, 1), | 132 | 2 | /*alpha_filtering=*/fuzztest::InRange<int>(0, 2), | 133 | 2 | /*alpha_quality=*/fuzztest::InRange<int>(0, 100), | 134 | 2 | /*pass=*/fuzztest::InRange<int>(1, 10), | 135 | 2 | /*preprocessing=*/fuzztest::InRange<int>(0, 2), | 136 | 2 | /*partitions=*/fuzztest::InRange<int>(0, 3), | 137 | 2 | /*partition_limit=*/fuzztest::InRange<int>(0, 10), | 138 | 2 | /*emulate_jpeg_size=*/fuzztest::InRange<int>(0, 1), | 139 | 2 | /*thread_level=*/fuzztest::InRange<int>(0, 1), | 140 | 2 | /*low_memory=*/fuzztest::InRange<int>(0, 1), | 141 | 2 | /*near_lossless=*/fuzztest::InRange<int>(0, 5), | 142 | 2 | /*exact=*/fuzztest::InRange<int>(0, 1), | 143 | 2 | /*use_delta_palette=*/fuzztest::InRange<int>(0, 1), | 144 | 2 | /*use_sharp_yuv=*/fuzztest::InRange<int>(0, 1)); | 145 | 2 | } |
animencoder_fuzzer.cc:fuzz_utils::ArbitraryWebPConfig() Line | Count | Source | 82 | 2 | static inline auto ArbitraryWebPConfig() { | 83 | 2 | return fuzztest::Map( | 84 | 2 | [](int lossless, int quality, int method, int image_hint, int segments, | 85 | 2 | int sns_strength, int filter_strength, int filter_sharpness, | 86 | 2 | int filter_type, int autofilter, int alpha_compression, | 87 | 2 | int alpha_filtering, int alpha_quality, int pass, int preprocessing, | 88 | 2 | int partitions, int partition_limit, int emulate_jpeg_size, | 89 | 2 | int thread_level, int low_memory, int near_lossless, int exact, | 90 | 2 | int use_delta_palette, int use_sharp_yuv) -> WebPConfig { | 91 | 2 | WebPConfig config; | 92 | 2 | if (!WebPConfigInit(&config)) abort(); | 93 | 2 | config.lossless = lossless; | 94 | 2 | config.quality = quality; | 95 | 2 | config.method = method; | 96 | 2 | config.image_hint = (WebPImageHint)image_hint; | 97 | 2 | config.segments = segments; | 98 | 2 | config.sns_strength = sns_strength; | 99 | 2 | config.filter_strength = filter_strength; | 100 | 2 | config.filter_sharpness = filter_sharpness; | 101 | 2 | config.filter_type = filter_type; | 102 | 2 | config.autofilter = autofilter; | 103 | 2 | config.alpha_compression = alpha_compression; | 104 | 2 | config.alpha_filtering = alpha_filtering; | 105 | 2 | config.alpha_quality = alpha_quality; | 106 | 2 | config.pass = pass; | 107 | 2 | config.show_compressed = 1; | 108 | 2 | config.preprocessing = preprocessing; | 109 | 2 | config.partitions = partitions; | 110 | 2 | config.partition_limit = 10 * partition_limit; | 111 | 2 | config.emulate_jpeg_size = emulate_jpeg_size; | 112 | 2 | config.thread_level = thread_level; | 113 | 2 | config.low_memory = low_memory; | 114 | 2 | config.near_lossless = 20 * near_lossless; | 115 | 2 | config.exact = exact; | 116 | 2 | config.use_delta_palette = use_delta_palette; | 117 | 2 | config.use_sharp_yuv = use_sharp_yuv; | 118 | 2 | if (!WebPValidateConfig(&config)) abort(); | 119 | 2 | return config; | 120 | 2 | }, | 121 | 2 | /*lossless=*/fuzztest::InRange<int>(0, 1), | 122 | 2 | /*quality=*/fuzztest::InRange<int>(0, 100), | 123 | 2 | /*method=*/fuzztest::InRange<int>(0, 6), | 124 | 2 | /*image_hint=*/fuzztest::InRange<int>(0, WEBP_HINT_LAST - 1), | 125 | 2 | /*segments=*/fuzztest::InRange<int>(1, 4), | 126 | 2 | /*sns_strength=*/fuzztest::InRange<int>(0, 100), | 127 | 2 | /*filter_strength=*/fuzztest::InRange<int>(0, 100), | 128 | 2 | /*filter_sharpness=*/fuzztest::InRange<int>(0, 7), | 129 | 2 | /*filter_type=*/fuzztest::InRange<int>(0, 1), | 130 | 2 | /*autofilter=*/fuzztest::InRange<int>(0, 1), | 131 | 2 | /*alpha_compression=*/fuzztest::InRange<int>(0, 1), | 132 | 2 | /*alpha_filtering=*/fuzztest::InRange<int>(0, 2), | 133 | 2 | /*alpha_quality=*/fuzztest::InRange<int>(0, 100), | 134 | 2 | /*pass=*/fuzztest::InRange<int>(1, 10), | 135 | 2 | /*preprocessing=*/fuzztest::InRange<int>(0, 2), | 136 | 2 | /*partitions=*/fuzztest::InRange<int>(0, 3), | 137 | 2 | /*partition_limit=*/fuzztest::InRange<int>(0, 10), | 138 | 2 | /*emulate_jpeg_size=*/fuzztest::InRange<int>(0, 1), | 139 | 2 | /*thread_level=*/fuzztest::InRange<int>(0, 1), | 140 | 2 | /*low_memory=*/fuzztest::InRange<int>(0, 1), | 141 | 2 | /*near_lossless=*/fuzztest::InRange<int>(0, 5), | 142 | 2 | /*exact=*/fuzztest::InRange<int>(0, 1), | 143 | 2 | /*use_delta_palette=*/fuzztest::InRange<int>(0, 1), | 144 | 2 | /*use_sharp_yuv=*/fuzztest::InRange<int>(0, 1)); | 145 | 2 | } |
Unexecuted instantiation: advanced_api_fuzzer.cc:fuzz_utils::ArbitraryWebPConfig() Unexecuted instantiation: simple_api_fuzzer.cc:fuzz_utils::ArbitraryWebPConfig() |
146 | | |
147 | | struct CropOrScaleParams { |
148 | | bool alter_input; |
149 | | bool crop_or_scale; |
150 | | int width_ratio; |
151 | | int height_ratio; |
152 | | int left_ratio; |
153 | | int top_ratio; |
154 | | }; |
155 | | |
156 | 6 | static inline auto ArbitraryCropOrScaleParams() { |
157 | 6 | return fuzztest::Map( |
158 | 6 | [](const std::optional<std::pair<int, int>>& width_height_ratio, |
159 | 6 | const std::optional<std::pair<int, int>>& left_top_ratio) |
160 | 26.2k | -> CropOrScaleParams { |
161 | 26.2k | CropOrScaleParams params; |
162 | 26.2k | params.alter_input = width_height_ratio.has_value(); |
163 | 26.2k | if (params.alter_input) { |
164 | 11.9k | params.width_ratio = width_height_ratio->first; |
165 | 11.9k | params.height_ratio = width_height_ratio->second; |
166 | 11.9k | params.crop_or_scale = left_top_ratio.has_value(); |
167 | 11.9k | if (params.crop_or_scale) { |
168 | 3.57k | params.left_ratio = left_top_ratio->first; |
169 | 3.57k | params.top_ratio = left_top_ratio->second; |
170 | 3.57k | } |
171 | 11.9k | } |
172 | 26.2k | return params; |
173 | 26.2k | }, enc_fuzzer.cc:fuzz_utils::ArbitraryCropOrScaleParams()::{lambda(std::__1::optional<std::__1::pair<int, int> > const&, std::__1::optional<std::__1::pair<int, int> > const&)#1}::operator()(std::__1::optional<std::__1::pair<int, int> > const&, std::__1::optional<std::__1::pair<int, int> > const&) const Line | Count | Source | 160 | 9.10k | -> CropOrScaleParams { | 161 | 9.10k | CropOrScaleParams params; | 162 | 9.10k | params.alter_input = width_height_ratio.has_value(); | 163 | 9.10k | if (params.alter_input) { | 164 | 3.46k | params.width_ratio = width_height_ratio->first; | 165 | 3.46k | params.height_ratio = width_height_ratio->second; | 166 | 3.46k | params.crop_or_scale = left_top_ratio.has_value(); | 167 | 3.46k | if (params.crop_or_scale) { | 168 | 711 | params.left_ratio = left_top_ratio->first; | 169 | 711 | params.top_ratio = left_top_ratio->second; | 170 | 711 | } | 171 | 3.46k | } | 172 | 9.10k | return params; | 173 | 9.10k | }, |
enc_dec_fuzzer.cc:fuzz_utils::ArbitraryCropOrScaleParams()::{lambda(std::__1::optional<std::__1::pair<int, int> > const&, std::__1::optional<std::__1::pair<int, int> > const&)#1}::operator()(std::__1::optional<std::__1::pair<int, int> > const&, std::__1::optional<std::__1::pair<int, int> > const&) const Line | Count | Source | 160 | 3.98k | -> CropOrScaleParams { | 161 | 3.98k | CropOrScaleParams params; | 162 | 3.98k | params.alter_input = width_height_ratio.has_value(); | 163 | 3.98k | if (params.alter_input) { | 164 | 2.64k | params.width_ratio = width_height_ratio->first; | 165 | 2.64k | params.height_ratio = width_height_ratio->second; | 166 | 2.64k | params.crop_or_scale = left_top_ratio.has_value(); | 167 | 2.64k | if (params.crop_or_scale) { | 168 | 951 | params.left_ratio = left_top_ratio->first; | 169 | 951 | params.top_ratio = left_top_ratio->second; | 170 | 951 | } | 171 | 2.64k | } | 172 | 3.98k | return params; | 173 | 3.98k | }, |
animencoder_fuzzer.cc:fuzz_utils::ArbitraryCropOrScaleParams()::{lambda(std::__1::optional<std::__1::pair<int, int> > const&, std::__1::optional<std::__1::pair<int, int> > const&)#1}::operator()(std::__1::optional<std::__1::pair<int, int> > const&, std::__1::optional<std::__1::pair<int, int> > const&) const Line | Count | Source | 160 | 13.1k | -> CropOrScaleParams { | 161 | 13.1k | CropOrScaleParams params; | 162 | 13.1k | params.alter_input = width_height_ratio.has_value(); | 163 | 13.1k | if (params.alter_input) { | 164 | 5.80k | params.width_ratio = width_height_ratio->first; | 165 | 5.80k | params.height_ratio = width_height_ratio->second; | 166 | 5.80k | params.crop_or_scale = left_top_ratio.has_value(); | 167 | 5.80k | if (params.crop_or_scale) { | 168 | 1.91k | params.left_ratio = left_top_ratio->first; | 169 | 1.91k | params.top_ratio = left_top_ratio->second; | 170 | 1.91k | } | 171 | 5.80k | } | 172 | 13.1k | return params; | 173 | 13.1k | }, |
|
174 | 6 | fuzztest::OptionalOf( |
175 | 6 | fuzztest::PairOf(fuzztest::InRange(1, 8), fuzztest::InRange(1, 8))), |
176 | 6 | fuzztest::OptionalOf( |
177 | 6 | fuzztest::PairOf(fuzztest::InRange(1, 8), fuzztest::InRange(1, 8)))); |
178 | 6 | } Unexecuted instantiation: mux_demux_api_fuzzer.cc:fuzz_utils::ArbitraryCropOrScaleParams() Unexecuted instantiation: imageio_fuzzer.cc:fuzz_utils::ArbitraryCropOrScaleParams() Unexecuted instantiation: fuzz_utils.cc:fuzz_utils::ArbitraryCropOrScaleParams() Unexecuted instantiation: huffman_fuzzer.cc:fuzz_utils::ArbitraryCropOrScaleParams() enc_fuzzer.cc:fuzz_utils::ArbitraryCropOrScaleParams() Line | Count | Source | 156 | 2 | static inline auto ArbitraryCropOrScaleParams() { | 157 | 2 | return fuzztest::Map( | 158 | 2 | [](const std::optional<std::pair<int, int>>& width_height_ratio, | 159 | 2 | const std::optional<std::pair<int, int>>& left_top_ratio) | 160 | 2 | -> CropOrScaleParams { | 161 | 2 | CropOrScaleParams params; | 162 | 2 | params.alter_input = width_height_ratio.has_value(); | 163 | 2 | if (params.alter_input) { | 164 | 2 | params.width_ratio = width_height_ratio->first; | 165 | 2 | params.height_ratio = width_height_ratio->second; | 166 | 2 | params.crop_or_scale = left_top_ratio.has_value(); | 167 | 2 | if (params.crop_or_scale) { | 168 | 2 | params.left_ratio = left_top_ratio->first; | 169 | 2 | params.top_ratio = left_top_ratio->second; | 170 | 2 | } | 171 | 2 | } | 172 | 2 | return params; | 173 | 2 | }, | 174 | 2 | fuzztest::OptionalOf( | 175 | 2 | fuzztest::PairOf(fuzztest::InRange(1, 8), fuzztest::InRange(1, 8))), | 176 | 2 | fuzztest::OptionalOf( | 177 | 2 | fuzztest::PairOf(fuzztest::InRange(1, 8), fuzztest::InRange(1, 8)))); | 178 | 2 | } |
Unexecuted instantiation: webp_info_fuzzer.cc:fuzz_utils::ArbitraryCropOrScaleParams() Unexecuted instantiation: animdecoder_fuzzer.cc:fuzz_utils::ArbitraryCropOrScaleParams() Unexecuted instantiation: animation_api_fuzzer.cc:fuzz_utils::ArbitraryCropOrScaleParams() Unexecuted instantiation: dec_fuzzer.cc:fuzz_utils::ArbitraryCropOrScaleParams() enc_dec_fuzzer.cc:fuzz_utils::ArbitraryCropOrScaleParams() Line | Count | Source | 156 | 2 | static inline auto ArbitraryCropOrScaleParams() { | 157 | 2 | return fuzztest::Map( | 158 | 2 | [](const std::optional<std::pair<int, int>>& width_height_ratio, | 159 | 2 | const std::optional<std::pair<int, int>>& left_top_ratio) | 160 | 2 | -> CropOrScaleParams { | 161 | 2 | CropOrScaleParams params; | 162 | 2 | params.alter_input = width_height_ratio.has_value(); | 163 | 2 | if (params.alter_input) { | 164 | 2 | params.width_ratio = width_height_ratio->first; | 165 | 2 | params.height_ratio = width_height_ratio->second; | 166 | 2 | params.crop_or_scale = left_top_ratio.has_value(); | 167 | 2 | if (params.crop_or_scale) { | 168 | 2 | params.left_ratio = left_top_ratio->first; | 169 | 2 | params.top_ratio = left_top_ratio->second; | 170 | 2 | } | 171 | 2 | } | 172 | 2 | return params; | 173 | 2 | }, | 174 | 2 | fuzztest::OptionalOf( | 175 | 2 | fuzztest::PairOf(fuzztest::InRange(1, 8), fuzztest::InRange(1, 8))), | 176 | 2 | fuzztest::OptionalOf( | 177 | 2 | fuzztest::PairOf(fuzztest::InRange(1, 8), fuzztest::InRange(1, 8)))); | 178 | 2 | } |
animencoder_fuzzer.cc:fuzz_utils::ArbitraryCropOrScaleParams() Line | Count | Source | 156 | 2 | static inline auto ArbitraryCropOrScaleParams() { | 157 | 2 | return fuzztest::Map( | 158 | 2 | [](const std::optional<std::pair<int, int>>& width_height_ratio, | 159 | 2 | const std::optional<std::pair<int, int>>& left_top_ratio) | 160 | 2 | -> CropOrScaleParams { | 161 | 2 | CropOrScaleParams params; | 162 | 2 | params.alter_input = width_height_ratio.has_value(); | 163 | 2 | if (params.alter_input) { | 164 | 2 | params.width_ratio = width_height_ratio->first; | 165 | 2 | params.height_ratio = width_height_ratio->second; | 166 | 2 | params.crop_or_scale = left_top_ratio.has_value(); | 167 | 2 | if (params.crop_or_scale) { | 168 | 2 | params.left_ratio = left_top_ratio->first; | 169 | 2 | params.top_ratio = left_top_ratio->second; | 170 | 2 | } | 171 | 2 | } | 172 | 2 | return params; | 173 | 2 | }, | 174 | 2 | fuzztest::OptionalOf( | 175 | 2 | fuzztest::PairOf(fuzztest::InRange(1, 8), fuzztest::InRange(1, 8))), | 176 | 2 | fuzztest::OptionalOf( | 177 | 2 | fuzztest::PairOf(fuzztest::InRange(1, 8), fuzztest::InRange(1, 8)))); | 178 | 2 | } |
Unexecuted instantiation: advanced_api_fuzzer.cc:fuzz_utils::ArbitraryCropOrScaleParams() Unexecuted instantiation: simple_api_fuzzer.cc:fuzz_utils::ArbitraryCropOrScaleParams() |
179 | | |
180 | | // Crops or scales a picture according to the given params. |
181 | | int CropOrScale(WebPPicture* pic, const CropOrScaleParams& params); |
182 | | |
183 | | // Imposes a level of optimization among one of the kMaxOptimizationIndex+1 |
184 | | // possible values: OnlyC, ForceSlowSSSE3, NoSSE41, NoAVX, default. |
185 | | static constexpr uint32_t kMaxOptimizationIndex = 4; |
186 | | void SetOptimization(VP8CPUInfo default_VP8GetCPUInfo, uint32_t index); |
187 | | |
188 | | //------------------------------------------------------------------------------ |
189 | | |
190 | | // See https://developers.google.com/speed/webp/docs/riff_container. |
191 | | static constexpr size_t kMaxWebPFileSize = (1ull << 32) - 2; // 4 GiB - 2 |
192 | | |
193 | | std::vector<std::string> GetDictionaryFromFiles( |
194 | | const std::vector<std::string_view>& file_paths); |
195 | | |
196 | | // Checks whether the binary blob containing a JPEG or WebP is too big for the |
197 | | // fuzzer. |
198 | | bool IsImageTooBig(const uint8_t* data, size_t size); |
199 | | |
200 | | } // namespace fuzz_utils |
201 | | |
202 | | #endif // WEBP_TESTS_FUZZER_FUZZ_UTILS_H_ |