/src/libwebp/tests/fuzzer/fuzz_utils.h
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright 2018 Google Inc. |
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 <stdint.h> |
21 | | #include <stdlib.h> |
22 | | |
23 | | #include "./img_alpha.h" |
24 | | #include "./img_grid.h" |
25 | | #include "./img_peak.h" |
26 | | #include "src/dsp/dsp.h" |
27 | | #include "src/webp/encode.h" |
28 | | |
29 | | //------------------------------------------------------------------------------ |
30 | | // Arbitrary limits to prevent OOM, timeout, or slow execution. |
31 | | |
32 | | // The decoded image size, and for animations additionally the canvas size. |
33 | | // Enabling some sanitizers slow down runtime significantly. |
34 | | // Use a very low threshold in this case to avoid timeouts. |
35 | | #if defined(__SANITIZE_ADDRESS__) // GCC |
36 | | static const size_t kFuzzPxLimit = 1024 * 1024 / 10; |
37 | | #elif !defined(__has_feature) // Clang |
38 | | static const size_t kFuzzPxLimit = 1024 * 1024; |
39 | | #elif __has_feature(address_sanitizer) || __has_feature(memory_sanitizer) |
40 | | static const size_t kFuzzPxLimit = 1024 * 1024 / 18; |
41 | | #else |
42 | | static const size_t kFuzzPxLimit = 1024 * 1024; |
43 | | #endif |
44 | | |
45 | | // Demuxed or decoded animation frames. |
46 | | static const int kFuzzFrameLimit = 3; |
47 | | |
48 | | // Reads and sums (up to) 128 spread-out bytes. |
49 | 13.3k | static WEBP_INLINE uint8_t FuzzHash(const uint8_t* const data, size_t size) { |
50 | 13.3k | uint8_t value = 0; |
51 | 13.3k | size_t incr = size / 128; |
52 | 13.3k | if (!incr) incr = 1; |
53 | 653k | for (size_t i = 0; i < size; i += incr) value += data[i]; |
54 | 13.3k | return value; |
55 | 13.3k | } Unexecuted instantiation: enc_dec_fuzzer.cc:FuzzHash(unsigned char const*, unsigned long) advanced_api_fuzzer.c:FuzzHash Line | Count | Source | 49 | 8.06k | static WEBP_INLINE uint8_t FuzzHash(const uint8_t* const data, size_t size) { | 50 | 8.06k | uint8_t value = 0; | 51 | 8.06k | size_t incr = size / 128; | 52 | 8.06k | if (!incr) incr = 1; | 53 | 416k | for (size_t i = 0; i < size; i += incr) value += data[i]; | 54 | 8.06k | return value; | 55 | 8.06k | } |
Unexecuted instantiation: mux_demux_api_fuzzer.c:FuzzHash Unexecuted instantiation: animencoder_fuzzer.cc:FuzzHash(unsigned char const*, unsigned long) simple_api_fuzzer.c:FuzzHash Line | Count | Source | 49 | 5.23k | static WEBP_INLINE uint8_t FuzzHash(const uint8_t* const data, size_t size) { | 50 | 5.23k | uint8_t value = 0; | 51 | 5.23k | size_t incr = size / 128; | 52 | 5.23k | if (!incr) incr = 1; | 53 | 236k | for (size_t i = 0; i < size; i += incr) value += data[i]; | 54 | 5.23k | return value; | 55 | 5.23k | } |
Unexecuted instantiation: animation_api_fuzzer.c:FuzzHash |
56 | | |
57 | | //------------------------------------------------------------------------------ |
58 | | // Extract an integer in [0, max_value]. |
59 | | |
60 | | static WEBP_INLINE uint32_t Extract(uint32_t max_value, |
61 | | const uint8_t data[], size_t size, |
62 | 1.51M | uint32_t* const bit_pos) { |
63 | 1.51M | uint32_t v = 0; |
64 | 1.51M | uint32_t range = 1; |
65 | 2.83M | while (*bit_pos < 8 * size && range <= max_value) { |
66 | 1.31M | const uint8_t mask = 1u << (*bit_pos & 7); |
67 | 1.31M | v = (v << 1) | !!(data[*bit_pos >> 3] & mask); |
68 | 1.31M | range <<= 1; |
69 | 1.31M | ++*bit_pos; |
70 | 1.31M | } |
71 | 1.51M | return v % (max_value + 1); |
72 | 1.51M | } enc_dec_fuzzer.cc:Extract(unsigned int, unsigned char const*, unsigned long, unsigned int*) Line | Count | Source | 62 | 142k | uint32_t* const bit_pos) { | 63 | 142k | uint32_t v = 0; | 64 | 142k | uint32_t range = 1; | 65 | 335k | while (*bit_pos < 8 * size && range <= max_value) { | 66 | 192k | const uint8_t mask = 1u << (*bit_pos & 7); | 67 | 192k | v = (v << 1) | !!(data[*bit_pos >> 3] & mask); | 68 | 192k | range <<= 1; | 69 | 192k | ++*bit_pos; | 70 | 192k | } | 71 | 142k | return v % (max_value + 1); | 72 | 142k | } |
Unexecuted instantiation: advanced_api_fuzzer.c:Extract Unexecuted instantiation: mux_demux_api_fuzzer.c:Extract animencoder_fuzzer.cc:Extract(unsigned int, unsigned char const*, unsigned long, unsigned int*) Line | Count | Source | 62 | 1.37M | uint32_t* const bit_pos) { | 63 | 1.37M | uint32_t v = 0; | 64 | 1.37M | uint32_t range = 1; | 65 | 2.49M | while (*bit_pos < 8 * size && range <= max_value) { | 66 | 1.12M | const uint8_t mask = 1u << (*bit_pos & 7); | 67 | 1.12M | v = (v << 1) | !!(data[*bit_pos >> 3] & mask); | 68 | 1.12M | range <<= 1; | 69 | 1.12M | ++*bit_pos; | 70 | 1.12M | } | 71 | 1.37M | return v % (max_value + 1); | 72 | 1.37M | } |
Unexecuted instantiation: simple_api_fuzzer.c:Extract Unexecuted instantiation: animation_api_fuzzer.c:Extract |
73 | | |
74 | | //------------------------------------------------------------------------------ |
75 | | // Some functions to override VP8GetCPUInfo and disable some optimizations. |
76 | | |
77 | | #ifdef __cplusplus |
78 | | extern "C" VP8CPUInfo VP8GetCPUInfo; |
79 | | #else |
80 | | extern VP8CPUInfo VP8GetCPUInfo; |
81 | | #endif |
82 | | static VP8CPUInfo GetCPUInfo; |
83 | | |
84 | 21.8k | static WEBP_INLINE int GetCPUInfoNoSSE41(CPUFeature feature) { |
85 | 21.8k | if (feature == kSSE4_1 || feature == kAVX) return 0; |
86 | 12.9k | return GetCPUInfo(feature); |
87 | 21.8k | } enc_dec_fuzzer.cc:GetCPUInfoNoSSE41(CPUFeature) Line | Count | Source | 84 | 9.04k | static WEBP_INLINE int GetCPUInfoNoSSE41(CPUFeature feature) { | 85 | 9.04k | if (feature == kSSE4_1 || feature == kAVX) return 0; | 86 | 5.19k | return GetCPUInfo(feature); | 87 | 9.04k | } |
Unexecuted instantiation: advanced_api_fuzzer.c:GetCPUInfoNoSSE41 Unexecuted instantiation: mux_demux_api_fuzzer.c:GetCPUInfoNoSSE41 animencoder_fuzzer.cc:GetCPUInfoNoSSE41(CPUFeature) Line | Count | Source | 84 | 12.8k | static WEBP_INLINE int GetCPUInfoNoSSE41(CPUFeature feature) { | 85 | 12.8k | if (feature == kSSE4_1 || feature == kAVX) return 0; | 86 | 7.75k | return GetCPUInfo(feature); | 87 | 12.8k | } |
Unexecuted instantiation: simple_api_fuzzer.c:GetCPUInfoNoSSE41 Unexecuted instantiation: animation_api_fuzzer.c:GetCPUInfoNoSSE41 |
88 | | |
89 | 13.2k | static WEBP_INLINE int GetCPUInfoNoAVX(CPUFeature feature) { |
90 | 13.2k | if (feature == kAVX) return 0; |
91 | 13.2k | return GetCPUInfo(feature); |
92 | 13.2k | } enc_dec_fuzzer.cc:GetCPUInfoNoAVX(CPUFeature) Line | Count | Source | 89 | 4.98k | static WEBP_INLINE int GetCPUInfoNoAVX(CPUFeature feature) { | 90 | 4.98k | if (feature == kAVX) return 0; | 91 | 4.98k | return GetCPUInfo(feature); | 92 | 4.98k | } |
Unexecuted instantiation: advanced_api_fuzzer.c:GetCPUInfoNoAVX Unexecuted instantiation: mux_demux_api_fuzzer.c:GetCPUInfoNoAVX animencoder_fuzzer.cc:GetCPUInfoNoAVX(CPUFeature) Line | Count | Source | 89 | 8.25k | static WEBP_INLINE int GetCPUInfoNoAVX(CPUFeature feature) { | 90 | 8.25k | if (feature == kAVX) return 0; | 91 | 8.25k | return GetCPUInfo(feature); | 92 | 8.25k | } |
Unexecuted instantiation: simple_api_fuzzer.c:GetCPUInfoNoAVX Unexecuted instantiation: animation_api_fuzzer.c:GetCPUInfoNoAVX |
93 | | |
94 | 18.7k | static WEBP_INLINE int GetCPUInfoForceSlowSSSE3(CPUFeature feature) { |
95 | 18.7k | if (feature == kSlowSSSE3 && GetCPUInfo(kSSE3)) { |
96 | 343 | return 1; // we have SSE3 -> force SlowSSSE3 |
97 | 343 | } |
98 | 18.3k | return GetCPUInfo(feature); |
99 | 18.7k | } enc_dec_fuzzer.cc:GetCPUInfoForceSlowSSSE3(CPUFeature) Line | Count | Source | 94 | 8.23k | static WEBP_INLINE int GetCPUInfoForceSlowSSSE3(CPUFeature feature) { | 95 | 8.23k | if (feature == kSlowSSSE3 && GetCPUInfo(kSSE3)) { | 96 | 343 | return 1; // we have SSE3 -> force SlowSSSE3 | 97 | 343 | } | 98 | 7.89k | return GetCPUInfo(feature); | 99 | 8.23k | } |
Unexecuted instantiation: advanced_api_fuzzer.c:GetCPUInfoForceSlowSSSE3 Unexecuted instantiation: mux_demux_api_fuzzer.c:GetCPUInfoForceSlowSSSE3 animencoder_fuzzer.cc:GetCPUInfoForceSlowSSSE3(CPUFeature) Line | Count | Source | 94 | 10.5k | static WEBP_INLINE int GetCPUInfoForceSlowSSSE3(CPUFeature feature) { | 95 | 10.5k | if (feature == kSlowSSSE3 && GetCPUInfo(kSSE3)) { | 96 | 0 | return 1; // we have SSE3 -> force SlowSSSE3 | 97 | 0 | } | 98 | 10.5k | return GetCPUInfo(feature); | 99 | 10.5k | } |
Unexecuted instantiation: simple_api_fuzzer.c:GetCPUInfoForceSlowSSSE3 Unexecuted instantiation: animation_api_fuzzer.c:GetCPUInfoForceSlowSSSE3 |
100 | | |
101 | 23.2k | static WEBP_INLINE int GetCPUInfoOnlyC(CPUFeature feature) { |
102 | 23.2k | (void)feature; |
103 | 23.2k | return 0; |
104 | 23.2k | } enc_dec_fuzzer.cc:GetCPUInfoOnlyC(CPUFeature) Line | Count | Source | 101 | 10.4k | static WEBP_INLINE int GetCPUInfoOnlyC(CPUFeature feature) { | 102 | 10.4k | (void)feature; | 103 | 10.4k | return 0; | 104 | 10.4k | } |
Unexecuted instantiation: advanced_api_fuzzer.c:GetCPUInfoOnlyC Unexecuted instantiation: mux_demux_api_fuzzer.c:GetCPUInfoOnlyC animencoder_fuzzer.cc:GetCPUInfoOnlyC(CPUFeature) Line | Count | Source | 101 | 12.8k | static WEBP_INLINE int GetCPUInfoOnlyC(CPUFeature feature) { | 102 | 12.8k | (void)feature; | 103 | 12.8k | return 0; | 104 | 12.8k | } |
Unexecuted instantiation: simple_api_fuzzer.c:GetCPUInfoOnlyC Unexecuted instantiation: animation_api_fuzzer.c:GetCPUInfoOnlyC |
105 | | |
106 | | static WEBP_INLINE void ExtractAndDisableOptimizations( |
107 | | VP8CPUInfo default_VP8GetCPUInfo, const uint8_t data[], size_t size, |
108 | 9.24k | uint32_t* const bit_pos) { |
109 | 9.24k | GetCPUInfo = default_VP8GetCPUInfo; |
110 | 9.24k | const VP8CPUInfo kVP8CPUInfos[5] = {GetCPUInfoOnlyC, GetCPUInfoForceSlowSSSE3, |
111 | 9.24k | GetCPUInfoNoSSE41, GetCPUInfoNoAVX, |
112 | 9.24k | GetCPUInfo}; |
113 | 9.24k | int VP8GetCPUInfo_index = Extract(4, data, size, bit_pos); |
114 | 9.24k | VP8GetCPUInfo = kVP8CPUInfos[VP8GetCPUInfo_index]; |
115 | 9.24k | } enc_dec_fuzzer.cc:ExtractAndDisableOptimizations(int (*)(CPUFeature), unsigned char const*, unsigned long, unsigned int*) Line | Count | Source | 108 | 4.50k | uint32_t* const bit_pos) { | 109 | 4.50k | GetCPUInfo = default_VP8GetCPUInfo; | 110 | 4.50k | const VP8CPUInfo kVP8CPUInfos[5] = {GetCPUInfoOnlyC, GetCPUInfoForceSlowSSSE3, | 111 | 4.50k | GetCPUInfoNoSSE41, GetCPUInfoNoAVX, | 112 | 4.50k | GetCPUInfo}; | 113 | 4.50k | int VP8GetCPUInfo_index = Extract(4, data, size, bit_pos); | 114 | 4.50k | VP8GetCPUInfo = kVP8CPUInfos[VP8GetCPUInfo_index]; | 115 | 4.50k | } |
Unexecuted instantiation: advanced_api_fuzzer.c:ExtractAndDisableOptimizations Unexecuted instantiation: mux_demux_api_fuzzer.c:ExtractAndDisableOptimizations animencoder_fuzzer.cc:ExtractAndDisableOptimizations(int (*)(CPUFeature), unsigned char const*, unsigned long, unsigned int*) Line | Count | Source | 108 | 4.73k | uint32_t* const bit_pos) { | 109 | 4.73k | GetCPUInfo = default_VP8GetCPUInfo; | 110 | 4.73k | const VP8CPUInfo kVP8CPUInfos[5] = {GetCPUInfoOnlyC, GetCPUInfoForceSlowSSSE3, | 111 | 4.73k | GetCPUInfoNoSSE41, GetCPUInfoNoAVX, | 112 | 4.73k | GetCPUInfo}; | 113 | 4.73k | int VP8GetCPUInfo_index = Extract(4, data, size, bit_pos); | 114 | 4.73k | VP8GetCPUInfo = kVP8CPUInfos[VP8GetCPUInfo_index]; | 115 | 4.73k | } |
Unexecuted instantiation: simple_api_fuzzer.c:ExtractAndDisableOptimizations Unexecuted instantiation: animation_api_fuzzer.c:ExtractAndDisableOptimizations |
116 | | |
117 | | //------------------------------------------------------------------------------ |
118 | | |
119 | | static WEBP_INLINE int ExtractWebPConfig(WebPConfig* const config, |
120 | | const uint8_t data[], size_t size, |
121 | 51.8k | uint32_t* const bit_pos) { |
122 | 51.8k | if (config == NULL || !WebPConfigInit(config)) return 0; |
123 | 51.8k | config->lossless = Extract(1, data, size, bit_pos); |
124 | 51.8k | config->quality = Extract(100, data, size, bit_pos); |
125 | 51.8k | config->method = Extract(6, data, size, bit_pos); |
126 | 51.8k | config->image_hint = |
127 | 51.8k | (WebPImageHint)Extract(WEBP_HINT_LAST - 1, data, size, bit_pos); |
128 | 51.8k | config->segments = 1 + Extract(3, data, size, bit_pos); |
129 | 51.8k | config->sns_strength = Extract(100, data, size, bit_pos); |
130 | 51.8k | config->filter_strength = Extract(100, data, size, bit_pos); |
131 | 51.8k | config->filter_sharpness = Extract(7, data, size, bit_pos); |
132 | 51.8k | config->filter_type = Extract(1, data, size, bit_pos); |
133 | 51.8k | config->autofilter = Extract(1, data, size, bit_pos); |
134 | 51.8k | config->alpha_compression = Extract(1, data, size, bit_pos); |
135 | 51.8k | config->alpha_filtering = Extract(2, data, size, bit_pos); |
136 | 51.8k | config->alpha_quality = Extract(100, data, size, bit_pos); |
137 | 51.8k | config->pass = 1 + Extract(9, data, size, bit_pos); |
138 | 51.8k | config->show_compressed = 1; |
139 | 51.8k | config->preprocessing = Extract(2, data, size, bit_pos); |
140 | 51.8k | config->partitions = Extract(3, data, size, bit_pos); |
141 | 51.8k | config->partition_limit = 10 * Extract(10, data, size, bit_pos); |
142 | 51.8k | config->emulate_jpeg_size = Extract(1, data, size, bit_pos); |
143 | 51.8k | config->thread_level = Extract(1, data, size, bit_pos); |
144 | 51.8k | config->low_memory = Extract(1, data, size, bit_pos); |
145 | 51.8k | config->near_lossless = 20 * Extract(5, data, size, bit_pos); |
146 | 51.8k | config->exact = Extract(1, data, size, bit_pos); |
147 | 51.8k | config->use_delta_palette = Extract(1, data, size, bit_pos); |
148 | 51.8k | config->use_sharp_yuv = Extract(1, data, size, bit_pos); |
149 | 51.8k | return WebPValidateConfig(config); |
150 | 51.8k | } enc_dec_fuzzer.cc:ExtractWebPConfig(WebPConfig*, unsigned char const*, unsigned long, unsigned int*) Line | Count | Source | 121 | 4.50k | uint32_t* const bit_pos) { | 122 | 4.50k | if (config == NULL || !WebPConfigInit(config)) return 0; | 123 | 4.50k | config->lossless = Extract(1, data, size, bit_pos); | 124 | 4.50k | config->quality = Extract(100, data, size, bit_pos); | 125 | 4.50k | config->method = Extract(6, data, size, bit_pos); | 126 | 4.50k | config->image_hint = | 127 | 4.50k | (WebPImageHint)Extract(WEBP_HINT_LAST - 1, data, size, bit_pos); | 128 | 4.50k | config->segments = 1 + Extract(3, data, size, bit_pos); | 129 | 4.50k | config->sns_strength = Extract(100, data, size, bit_pos); | 130 | 4.50k | config->filter_strength = Extract(100, data, size, bit_pos); | 131 | 4.50k | config->filter_sharpness = Extract(7, data, size, bit_pos); | 132 | 4.50k | config->filter_type = Extract(1, data, size, bit_pos); | 133 | 4.50k | config->autofilter = Extract(1, data, size, bit_pos); | 134 | 4.50k | config->alpha_compression = Extract(1, data, size, bit_pos); | 135 | 4.50k | config->alpha_filtering = Extract(2, data, size, bit_pos); | 136 | 4.50k | config->alpha_quality = Extract(100, data, size, bit_pos); | 137 | 4.50k | config->pass = 1 + Extract(9, data, size, bit_pos); | 138 | 4.50k | config->show_compressed = 1; | 139 | 4.50k | config->preprocessing = Extract(2, data, size, bit_pos); | 140 | 4.50k | config->partitions = Extract(3, data, size, bit_pos); | 141 | 4.50k | config->partition_limit = 10 * Extract(10, data, size, bit_pos); | 142 | 4.50k | config->emulate_jpeg_size = Extract(1, data, size, bit_pos); | 143 | 4.50k | config->thread_level = Extract(1, data, size, bit_pos); | 144 | 4.50k | config->low_memory = Extract(1, data, size, bit_pos); | 145 | 4.50k | config->near_lossless = 20 * Extract(5, data, size, bit_pos); | 146 | 4.50k | config->exact = Extract(1, data, size, bit_pos); | 147 | 4.50k | config->use_delta_palette = Extract(1, data, size, bit_pos); | 148 | 4.50k | config->use_sharp_yuv = Extract(1, data, size, bit_pos); | 149 | 4.50k | return WebPValidateConfig(config); | 150 | 4.50k | } |
Unexecuted instantiation: advanced_api_fuzzer.c:ExtractWebPConfig Unexecuted instantiation: mux_demux_api_fuzzer.c:ExtractWebPConfig animencoder_fuzzer.cc:ExtractWebPConfig(WebPConfig*, unsigned char const*, unsigned long, unsigned int*) Line | Count | Source | 121 | 47.3k | uint32_t* const bit_pos) { | 122 | 47.3k | if (config == NULL || !WebPConfigInit(config)) return 0; | 123 | 47.3k | config->lossless = Extract(1, data, size, bit_pos); | 124 | 47.3k | config->quality = Extract(100, data, size, bit_pos); | 125 | 47.3k | config->method = Extract(6, data, size, bit_pos); | 126 | 47.3k | config->image_hint = | 127 | 47.3k | (WebPImageHint)Extract(WEBP_HINT_LAST - 1, data, size, bit_pos); | 128 | 47.3k | config->segments = 1 + Extract(3, data, size, bit_pos); | 129 | 47.3k | config->sns_strength = Extract(100, data, size, bit_pos); | 130 | 47.3k | config->filter_strength = Extract(100, data, size, bit_pos); | 131 | 47.3k | config->filter_sharpness = Extract(7, data, size, bit_pos); | 132 | 47.3k | config->filter_type = Extract(1, data, size, bit_pos); | 133 | 47.3k | config->autofilter = Extract(1, data, size, bit_pos); | 134 | 47.3k | config->alpha_compression = Extract(1, data, size, bit_pos); | 135 | 47.3k | config->alpha_filtering = Extract(2, data, size, bit_pos); | 136 | 47.3k | config->alpha_quality = Extract(100, data, size, bit_pos); | 137 | 47.3k | config->pass = 1 + Extract(9, data, size, bit_pos); | 138 | 47.3k | config->show_compressed = 1; | 139 | 47.3k | config->preprocessing = Extract(2, data, size, bit_pos); | 140 | 47.3k | config->partitions = Extract(3, data, size, bit_pos); | 141 | 47.3k | config->partition_limit = 10 * Extract(10, data, size, bit_pos); | 142 | 47.3k | config->emulate_jpeg_size = Extract(1, data, size, bit_pos); | 143 | 47.3k | config->thread_level = Extract(1, data, size, bit_pos); | 144 | 47.3k | config->low_memory = Extract(1, data, size, bit_pos); | 145 | 47.3k | config->near_lossless = 20 * Extract(5, data, size, bit_pos); | 146 | 47.3k | config->exact = Extract(1, data, size, bit_pos); | 147 | 47.3k | config->use_delta_palette = Extract(1, data, size, bit_pos); | 148 | 47.3k | config->use_sharp_yuv = Extract(1, data, size, bit_pos); | 149 | 47.3k | return WebPValidateConfig(config); | 150 | 47.3k | } |
Unexecuted instantiation: simple_api_fuzzer.c:ExtractWebPConfig Unexecuted instantiation: animation_api_fuzzer.c:ExtractWebPConfig |
151 | | |
152 | | //------------------------------------------------------------------------------ |
153 | | |
154 | | static WEBP_INLINE int ExtractSourcePicture(WebPPicture* const pic, |
155 | | const uint8_t data[], size_t size, |
156 | 51.8k | uint32_t* const bit_pos) { |
157 | 51.8k | if (pic == NULL) return 0; |
158 | | |
159 | | // Pick a source picture. |
160 | 51.8k | const uint8_t* kImagesData[] = { |
161 | 51.8k | kImgAlphaData, |
162 | 51.8k | kImgGridData, |
163 | 51.8k | kImgPeakData |
164 | 51.8k | }; |
165 | 51.8k | const int kImagesWidth[] = { |
166 | 51.8k | kImgAlphaWidth, |
167 | 51.8k | kImgGridWidth, |
168 | 51.8k | kImgPeakWidth |
169 | 51.8k | }; |
170 | 51.8k | const int kImagesHeight[] = { |
171 | 51.8k | kImgAlphaHeight, |
172 | 51.8k | kImgGridHeight, |
173 | 51.8k | kImgPeakHeight |
174 | 51.8k | }; |
175 | 51.8k | const size_t kNbImages = sizeof(kImagesData) / sizeof(kImagesData[0]); |
176 | 51.8k | const size_t image_index = Extract(kNbImages - 1, data, size, bit_pos); |
177 | 51.8k | const uint8_t* const image_data = kImagesData[image_index]; |
178 | 51.8k | pic->width = kImagesWidth[image_index]; |
179 | 51.8k | pic->height = kImagesHeight[image_index]; |
180 | 51.8k | pic->argb_stride = pic->width * 4 * sizeof(uint8_t); |
181 | | |
182 | | // Read the bytes. |
183 | 51.8k | return WebPPictureImportRGBA(pic, image_data, pic->argb_stride); |
184 | 51.8k | } enc_dec_fuzzer.cc:ExtractSourcePicture(WebPPicture*, unsigned char const*, unsigned long, unsigned int*) Line | Count | Source | 156 | 4.50k | uint32_t* const bit_pos) { | 157 | 4.50k | if (pic == NULL) return 0; | 158 | | | 159 | | // Pick a source picture. | 160 | 4.50k | const uint8_t* kImagesData[] = { | 161 | 4.50k | kImgAlphaData, | 162 | 4.50k | kImgGridData, | 163 | 4.50k | kImgPeakData | 164 | 4.50k | }; | 165 | 4.50k | const int kImagesWidth[] = { | 166 | 4.50k | kImgAlphaWidth, | 167 | 4.50k | kImgGridWidth, | 168 | 4.50k | kImgPeakWidth | 169 | 4.50k | }; | 170 | 4.50k | const int kImagesHeight[] = { | 171 | 4.50k | kImgAlphaHeight, | 172 | 4.50k | kImgGridHeight, | 173 | 4.50k | kImgPeakHeight | 174 | 4.50k | }; | 175 | 4.50k | const size_t kNbImages = sizeof(kImagesData) / sizeof(kImagesData[0]); | 176 | 4.50k | const size_t image_index = Extract(kNbImages - 1, data, size, bit_pos); | 177 | 4.50k | const uint8_t* const image_data = kImagesData[image_index]; | 178 | 4.50k | pic->width = kImagesWidth[image_index]; | 179 | 4.50k | pic->height = kImagesHeight[image_index]; | 180 | 4.50k | pic->argb_stride = pic->width * 4 * sizeof(uint8_t); | 181 | | | 182 | | // Read the bytes. | 183 | 4.50k | return WebPPictureImportRGBA(pic, image_data, pic->argb_stride); | 184 | 4.50k | } |
Unexecuted instantiation: advanced_api_fuzzer.c:ExtractSourcePicture Unexecuted instantiation: mux_demux_api_fuzzer.c:ExtractSourcePicture animencoder_fuzzer.cc:ExtractSourcePicture(WebPPicture*, unsigned char const*, unsigned long, unsigned int*) Line | Count | Source | 156 | 47.3k | uint32_t* const bit_pos) { | 157 | 47.3k | if (pic == NULL) return 0; | 158 | | | 159 | | // Pick a source picture. | 160 | 47.3k | const uint8_t* kImagesData[] = { | 161 | 47.3k | kImgAlphaData, | 162 | 47.3k | kImgGridData, | 163 | 47.3k | kImgPeakData | 164 | 47.3k | }; | 165 | 47.3k | const int kImagesWidth[] = { | 166 | 47.3k | kImgAlphaWidth, | 167 | 47.3k | kImgGridWidth, | 168 | 47.3k | kImgPeakWidth | 169 | 47.3k | }; | 170 | 47.3k | const int kImagesHeight[] = { | 171 | 47.3k | kImgAlphaHeight, | 172 | 47.3k | kImgGridHeight, | 173 | 47.3k | kImgPeakHeight | 174 | 47.3k | }; | 175 | 47.3k | const size_t kNbImages = sizeof(kImagesData) / sizeof(kImagesData[0]); | 176 | 47.3k | const size_t image_index = Extract(kNbImages - 1, data, size, bit_pos); | 177 | 47.3k | const uint8_t* const image_data = kImagesData[image_index]; | 178 | 47.3k | pic->width = kImagesWidth[image_index]; | 179 | 47.3k | pic->height = kImagesHeight[image_index]; | 180 | 47.3k | pic->argb_stride = pic->width * 4 * sizeof(uint8_t); | 181 | | | 182 | | // Read the bytes. | 183 | 47.3k | return WebPPictureImportRGBA(pic, image_data, pic->argb_stride); | 184 | 47.3k | } |
Unexecuted instantiation: simple_api_fuzzer.c:ExtractSourcePicture Unexecuted instantiation: animation_api_fuzzer.c:ExtractSourcePicture |
185 | | |
186 | | //------------------------------------------------------------------------------ |
187 | | |
188 | 5.79k | static WEBP_INLINE int Max(int a, int b) { return ((a < b) ? b : a); } enc_dec_fuzzer.cc:Max(int, int) Line | Count | Source | 188 | 2.59k | static WEBP_INLINE int Max(int a, int b) { return ((a < b) ? b : a); } |
advanced_api_fuzzer.c:Max Line | Count | Source | 188 | 666 | static WEBP_INLINE int Max(int a, int b) { return ((a < b) ? b : a); } |
Unexecuted instantiation: mux_demux_api_fuzzer.c:Max animencoder_fuzzer.cc:Max(int, int) Line | Count | Source | 188 | 2.53k | static WEBP_INLINE int Max(int a, int b) { return ((a < b) ? b : a); } |
Unexecuted instantiation: simple_api_fuzzer.c:Max Unexecuted instantiation: animation_api_fuzzer.c:Max |
189 | | |
190 | | static WEBP_INLINE int ExtractAndCropOrScale(WebPPicture* const pic, |
191 | | const uint8_t data[], size_t size, |
192 | 9.24k | uint32_t* const bit_pos) { |
193 | 9.24k | if (pic == NULL) return 0; |
194 | 9.24k | #if !defined(WEBP_REDUCE_SIZE) |
195 | 9.24k | const int alter_input = Extract(1, data, size, bit_pos); |
196 | 9.24k | const int crop_or_scale = Extract(1, data, size, bit_pos); |
197 | 9.24k | const int width_ratio = 1 + Extract(7, data, size, bit_pos); |
198 | 9.24k | const int height_ratio = 1 + Extract(7, data, size, bit_pos); |
199 | 9.24k | if (alter_input) { |
200 | 7.81k | if (crop_or_scale) { |
201 | 2.56k | const uint32_t left_ratio = 1 + Extract(7, data, size, bit_pos); |
202 | 2.56k | const uint32_t top_ratio = 1 + Extract(7, data, size, bit_pos); |
203 | 2.56k | const int cropped_width = Max(1, pic->width / width_ratio); |
204 | 2.56k | const int cropped_height = Max(1, pic->height / height_ratio); |
205 | 2.56k | const int cropped_left = (pic->width - cropped_width) / left_ratio; |
206 | 2.56k | const int cropped_top = (pic->height - cropped_height) / top_ratio; |
207 | 2.56k | return WebPPictureCrop(pic, cropped_left, cropped_top, cropped_width, |
208 | 2.56k | cropped_height); |
209 | 5.24k | } else { |
210 | 5.24k | const int scaled_width = 1 + (pic->width * width_ratio) / 8; |
211 | 5.24k | const int scaled_height = 1 + (pic->height * height_ratio) / 8; |
212 | 5.24k | return WebPPictureRescale(pic, scaled_width, scaled_height); |
213 | 5.24k | } |
214 | 7.81k | } |
215 | | #else // defined(WEBP_REDUCE_SIZE) |
216 | | (void)data; |
217 | | (void)size; |
218 | | (void)bit_pos; |
219 | | #endif // !defined(WEBP_REDUCE_SIZE) |
220 | 1.42k | return 1; |
221 | 9.24k | } enc_dec_fuzzer.cc:ExtractAndCropOrScale(WebPPicture*, unsigned char const*, unsigned long, unsigned int*) Line | Count | Source | 192 | 4.50k | uint32_t* const bit_pos) { | 193 | 4.50k | if (pic == NULL) return 0; | 194 | 4.50k | #if !defined(WEBP_REDUCE_SIZE) | 195 | 4.50k | const int alter_input = Extract(1, data, size, bit_pos); | 196 | 4.50k | const int crop_or_scale = Extract(1, data, size, bit_pos); | 197 | 4.50k | const int width_ratio = 1 + Extract(7, data, size, bit_pos); | 198 | 4.50k | const int height_ratio = 1 + Extract(7, data, size, bit_pos); | 199 | 4.50k | if (alter_input) { | 200 | 3.94k | if (crop_or_scale) { | 201 | 1.29k | const uint32_t left_ratio = 1 + Extract(7, data, size, bit_pos); | 202 | 1.29k | const uint32_t top_ratio = 1 + Extract(7, data, size, bit_pos); | 203 | 1.29k | const int cropped_width = Max(1, pic->width / width_ratio); | 204 | 1.29k | const int cropped_height = Max(1, pic->height / height_ratio); | 205 | 1.29k | const int cropped_left = (pic->width - cropped_width) / left_ratio; | 206 | 1.29k | const int cropped_top = (pic->height - cropped_height) / top_ratio; | 207 | 1.29k | return WebPPictureCrop(pic, cropped_left, cropped_top, cropped_width, | 208 | 1.29k | cropped_height); | 209 | 2.65k | } else { | 210 | 2.65k | const int scaled_width = 1 + (pic->width * width_ratio) / 8; | 211 | 2.65k | const int scaled_height = 1 + (pic->height * height_ratio) / 8; | 212 | 2.65k | return WebPPictureRescale(pic, scaled_width, scaled_height); | 213 | 2.65k | } | 214 | 3.94k | } | 215 | | #else // defined(WEBP_REDUCE_SIZE) | 216 | | (void)data; | 217 | | (void)size; | 218 | | (void)bit_pos; | 219 | | #endif // !defined(WEBP_REDUCE_SIZE) | 220 | 555 | return 1; | 221 | 4.50k | } |
Unexecuted instantiation: advanced_api_fuzzer.c:ExtractAndCropOrScale Unexecuted instantiation: mux_demux_api_fuzzer.c:ExtractAndCropOrScale animencoder_fuzzer.cc:ExtractAndCropOrScale(WebPPicture*, unsigned char const*, unsigned long, unsigned int*) Line | Count | Source | 192 | 4.73k | uint32_t* const bit_pos) { | 193 | 4.73k | if (pic == NULL) return 0; | 194 | 4.73k | #if !defined(WEBP_REDUCE_SIZE) | 195 | 4.73k | const int alter_input = Extract(1, data, size, bit_pos); | 196 | 4.73k | const int crop_or_scale = Extract(1, data, size, bit_pos); | 197 | 4.73k | const int width_ratio = 1 + Extract(7, data, size, bit_pos); | 198 | 4.73k | const int height_ratio = 1 + Extract(7, data, size, bit_pos); | 199 | 4.73k | if (alter_input) { | 200 | 3.86k | if (crop_or_scale) { | 201 | 1.26k | const uint32_t left_ratio = 1 + Extract(7, data, size, bit_pos); | 202 | 1.26k | const uint32_t top_ratio = 1 + Extract(7, data, size, bit_pos); | 203 | 1.26k | const int cropped_width = Max(1, pic->width / width_ratio); | 204 | 1.26k | const int cropped_height = Max(1, pic->height / height_ratio); | 205 | 1.26k | const int cropped_left = (pic->width - cropped_width) / left_ratio; | 206 | 1.26k | const int cropped_top = (pic->height - cropped_height) / top_ratio; | 207 | 1.26k | return WebPPictureCrop(pic, cropped_left, cropped_top, cropped_width, | 208 | 1.26k | cropped_height); | 209 | 2.59k | } else { | 210 | 2.59k | const int scaled_width = 1 + (pic->width * width_ratio) / 8; | 211 | 2.59k | const int scaled_height = 1 + (pic->height * height_ratio) / 8; | 212 | 2.59k | return WebPPictureRescale(pic, scaled_width, scaled_height); | 213 | 2.59k | } | 214 | 3.86k | } | 215 | | #else // defined(WEBP_REDUCE_SIZE) | 216 | | (void)data; | 217 | | (void)size; | 218 | | (void)bit_pos; | 219 | | #endif // !defined(WEBP_REDUCE_SIZE) | 220 | 872 | return 1; | 221 | 4.73k | } |
Unexecuted instantiation: simple_api_fuzzer.c:ExtractAndCropOrScale Unexecuted instantiation: animation_api_fuzzer.c:ExtractAndCropOrScale |
222 | | |
223 | | #endif // WEBP_TESTS_FUZZER_FUZZ_UTILS_H_ |