Coverage Report

Created: 2023-09-01 06:48

/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.9k
static WEBP_INLINE uint8_t FuzzHash(const uint8_t* const data, size_t size) {
50
13.9k
  uint8_t value = 0;
51
13.9k
  size_t incr = size / 128;
52
13.9k
  if (!incr) incr = 1;
53
668k
  for (size_t i = 0; i < size; i += incr) value += data[i];
54
13.9k
  return value;
55
13.9k
}
Unexecuted instantiation: enc_dec_fuzzer.cc:FuzzHash(unsigned char const*, unsigned long)
simple_api_fuzzer.c:FuzzHash
Line
Count
Source
49
5.55k
static WEBP_INLINE uint8_t FuzzHash(const uint8_t* const data, size_t size) {
50
5.55k
  uint8_t value = 0;
51
5.55k
  size_t incr = size / 128;
52
5.55k
  if (!incr) incr = 1;
53
238k
  for (size_t i = 0; i < size; i += incr) value += data[i];
54
5.55k
  return value;
55
5.55k
}
Unexecuted instantiation: mux_demux_api_fuzzer.c:FuzzHash
Unexecuted instantiation: animencoder_fuzzer.cc:FuzzHash(unsigned char const*, unsigned long)
Unexecuted instantiation: animation_api_fuzzer.c:FuzzHash
advanced_api_fuzzer.c:FuzzHash
Line
Count
Source
49
8.43k
static WEBP_INLINE uint8_t FuzzHash(const uint8_t* const data, size_t size) {
50
8.43k
  uint8_t value = 0;
51
8.43k
  size_t incr = size / 128;
52
8.43k
  if (!incr) incr = 1;
53
430k
  for (size_t i = 0; i < size; i += incr) value += data[i];
54
8.43k
  return value;
55
8.43k
}
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.52M
                                    uint32_t* const bit_pos) {
63
1.52M
  uint32_t v = 0;
64
1.52M
  uint32_t range = 1;
65
2.84M
  while (*bit_pos < 8 * size && range <= max_value) {
66
1.32M
    const uint8_t mask = 1u << (*bit_pos & 7);
67
1.32M
    v = (v << 1) | !!(data[*bit_pos >> 3] & mask);
68
1.32M
    range <<= 1;
69
1.32M
    ++*bit_pos;
70
1.32M
  }
71
1.52M
  return v % (max_value + 1);
72
1.52M
}
enc_dec_fuzzer.cc:Extract(unsigned int, unsigned char const*, unsigned long, unsigned int*)
Line
Count
Source
62
151k
                                    uint32_t* const bit_pos) {
63
151k
  uint32_t v = 0;
64
151k
  uint32_t range = 1;
65
353k
  while (*bit_pos < 8 * size && range <= max_value) {
66
202k
    const uint8_t mask = 1u << (*bit_pos & 7);
67
202k
    v = (v << 1) | !!(data[*bit_pos >> 3] & mask);
68
202k
    range <<= 1;
69
202k
    ++*bit_pos;
70
202k
  }
71
151k
  return v % (max_value + 1);
72
151k
}
Unexecuted instantiation: simple_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: animation_api_fuzzer.c:Extract
Unexecuted instantiation: advanced_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
23.5k
static WEBP_INLINE int GetCPUInfoNoSSE41(CPUFeature feature) {
85
23.5k
  if (feature == kSSE4_1 || feature == kAVX) return 0;
86
13.9k
  return GetCPUInfo(feature);
87
23.5k
}
enc_dec_fuzzer.cc:GetCPUInfoNoSSE41(CPUFeature)
Line
Count
Source
84
10.0k
static WEBP_INLINE int GetCPUInfoNoSSE41(CPUFeature feature) {
85
10.0k
  if (feature == kSSE4_1 || feature == kAVX) return 0;
86
5.79k
  return GetCPUInfo(feature);
87
10.0k
}
Unexecuted instantiation: simple_api_fuzzer.c:GetCPUInfoNoSSE41
Unexecuted instantiation: mux_demux_api_fuzzer.c:GetCPUInfoNoSSE41
animencoder_fuzzer.cc:GetCPUInfoNoSSE41(CPUFeature)
Line
Count
Source
84
13.5k
static WEBP_INLINE int GetCPUInfoNoSSE41(CPUFeature feature) {
85
13.5k
  if (feature == kSSE4_1 || feature == kAVX) return 0;
86
8.16k
  return GetCPUInfo(feature);
87
13.5k
}
Unexecuted instantiation: animation_api_fuzzer.c:GetCPUInfoNoSSE41
Unexecuted instantiation: advanced_api_fuzzer.c:GetCPUInfoNoSSE41
88
89
12.6k
static WEBP_INLINE int GetCPUInfoNoAVX(CPUFeature feature) {
90
12.6k
  if (feature == kAVX) return 0;
91
12.6k
  return GetCPUInfo(feature);
92
12.6k
}
enc_dec_fuzzer.cc:GetCPUInfoNoAVX(CPUFeature)
Line
Count
Source
89
5.19k
static WEBP_INLINE int GetCPUInfoNoAVX(CPUFeature feature) {
90
5.19k
  if (feature == kAVX) return 0;
91
5.19k
  return GetCPUInfo(feature);
92
5.19k
}
Unexecuted instantiation: simple_api_fuzzer.c:GetCPUInfoNoAVX
Unexecuted instantiation: mux_demux_api_fuzzer.c:GetCPUInfoNoAVX
animencoder_fuzzer.cc:GetCPUInfoNoAVX(CPUFeature)
Line
Count
Source
89
7.46k
static WEBP_INLINE int GetCPUInfoNoAVX(CPUFeature feature) {
90
7.46k
  if (feature == kAVX) return 0;
91
7.46k
  return GetCPUInfo(feature);
92
7.46k
}
Unexecuted instantiation: animation_api_fuzzer.c:GetCPUInfoNoAVX
Unexecuted instantiation: advanced_api_fuzzer.c:GetCPUInfoNoAVX
93
94
18.8k
static WEBP_INLINE int GetCPUInfoForceSlowSSSE3(CPUFeature feature) {
95
18.8k
  if (feature == kSlowSSSE3 && GetCPUInfo(kSSE3)) {
96
361
    return 1;  // we have SSE3 -> force SlowSSSE3
97
361
  }
98
18.4k
  return GetCPUInfo(feature);
99
18.8k
}
enc_dec_fuzzer.cc:GetCPUInfoForceSlowSSSE3(CPUFeature)
Line
Count
Source
94
8.66k
static WEBP_INLINE int GetCPUInfoForceSlowSSSE3(CPUFeature feature) {
95
8.66k
  if (feature == kSlowSSSE3 && GetCPUInfo(kSSE3)) {
96
361
    return 1;  // we have SSE3 -> force SlowSSSE3
97
361
  }
98
8.29k
  return GetCPUInfo(feature);
99
8.66k
}
Unexecuted instantiation: simple_api_fuzzer.c:GetCPUInfoForceSlowSSSE3
Unexecuted instantiation: mux_demux_api_fuzzer.c:GetCPUInfoForceSlowSSSE3
animencoder_fuzzer.cc:GetCPUInfoForceSlowSSSE3(CPUFeature)
Line
Count
Source
94
10.1k
static WEBP_INLINE int GetCPUInfoForceSlowSSSE3(CPUFeature feature) {
95
10.1k
  if (feature == kSlowSSSE3 && GetCPUInfo(kSSE3)) {
96
0
    return 1;  // we have SSE3 -> force SlowSSSE3
97
0
  }
98
10.1k
  return GetCPUInfo(feature);
99
10.1k
}
Unexecuted instantiation: animation_api_fuzzer.c:GetCPUInfoForceSlowSSSE3
Unexecuted instantiation: advanced_api_fuzzer.c:GetCPUInfoForceSlowSSSE3
100
101
24.0k
static WEBP_INLINE int GetCPUInfoOnlyC(CPUFeature feature) {
102
24.0k
  (void)feature;
103
24.0k
  return 0;
104
24.0k
}
enc_dec_fuzzer.cc:GetCPUInfoOnlyC(CPUFeature)
Line
Count
Source
101
11.5k
static WEBP_INLINE int GetCPUInfoOnlyC(CPUFeature feature) {
102
11.5k
  (void)feature;
103
11.5k
  return 0;
104
11.5k
}
Unexecuted instantiation: simple_api_fuzzer.c:GetCPUInfoOnlyC
Unexecuted instantiation: mux_demux_api_fuzzer.c:GetCPUInfoOnlyC
animencoder_fuzzer.cc:GetCPUInfoOnlyC(CPUFeature)
Line
Count
Source
101
12.4k
static WEBP_INLINE int GetCPUInfoOnlyC(CPUFeature feature) {
102
12.4k
  (void)feature;
103
12.4k
  return 0;
104
12.4k
}
Unexecuted instantiation: animation_api_fuzzer.c:GetCPUInfoOnlyC
Unexecuted instantiation: advanced_api_fuzzer.c:GetCPUInfoOnlyC
105
106
static WEBP_INLINE void ExtractAndDisableOptimizations(
107
    VP8CPUInfo default_VP8GetCPUInfo, const uint8_t data[], size_t size,
108
9.49k
    uint32_t* const bit_pos) {
109
9.49k
  GetCPUInfo = default_VP8GetCPUInfo;
110
9.49k
  const VP8CPUInfo kVP8CPUInfos[5] = {GetCPUInfoOnlyC, GetCPUInfoForceSlowSSSE3,
111
9.49k
                                      GetCPUInfoNoSSE41, GetCPUInfoNoAVX,
112
9.49k
                                      GetCPUInfo};
113
9.49k
  int VP8GetCPUInfo_index = Extract(4, data, size, bit_pos);
114
9.49k
  VP8GetCPUInfo = kVP8CPUInfos[VP8GetCPUInfo_index];
115
9.49k
}
enc_dec_fuzzer.cc:ExtractAndDisableOptimizations(int (*)(CPUFeature), unsigned char const*, unsigned long, unsigned int*)
Line
Count
Source
108
4.79k
    uint32_t* const bit_pos) {
109
4.79k
  GetCPUInfo = default_VP8GetCPUInfo;
110
4.79k
  const VP8CPUInfo kVP8CPUInfos[5] = {GetCPUInfoOnlyC, GetCPUInfoForceSlowSSSE3,
111
4.79k
                                      GetCPUInfoNoSSE41, GetCPUInfoNoAVX,
112
4.79k
                                      GetCPUInfo};
113
4.79k
  int VP8GetCPUInfo_index = Extract(4, data, size, bit_pos);
114
4.79k
  VP8GetCPUInfo = kVP8CPUInfos[VP8GetCPUInfo_index];
115
4.79k
}
Unexecuted instantiation: simple_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.69k
    uint32_t* const bit_pos) {
109
4.69k
  GetCPUInfo = default_VP8GetCPUInfo;
110
4.69k
  const VP8CPUInfo kVP8CPUInfos[5] = {GetCPUInfoOnlyC, GetCPUInfoForceSlowSSSE3,
111
4.69k
                                      GetCPUInfoNoSSE41, GetCPUInfoNoAVX,
112
4.69k
                                      GetCPUInfo};
113
4.69k
  int VP8GetCPUInfo_index = Extract(4, data, size, bit_pos);
114
4.69k
  VP8GetCPUInfo = kVP8CPUInfos[VP8GetCPUInfo_index];
115
4.69k
}
Unexecuted instantiation: animation_api_fuzzer.c:ExtractAndDisableOptimizations
Unexecuted instantiation: advanced_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.9k
                                         uint32_t* const bit_pos) {
122
51.9k
  if (config == NULL || !WebPConfigInit(config)) return 0;
123
51.9k
  config->lossless = Extract(1, data, size, bit_pos);
124
51.9k
  config->quality = Extract(100, data, size, bit_pos);
125
51.9k
  config->method = Extract(6, data, size, bit_pos);
126
51.9k
  config->image_hint =
127
51.9k
      (WebPImageHint)Extract(WEBP_HINT_LAST - 1, data, size, bit_pos);
128
51.9k
  config->segments = 1 + Extract(3, data, size, bit_pos);
129
51.9k
  config->sns_strength = Extract(100, data, size, bit_pos);
130
51.9k
  config->filter_strength = Extract(100, data, size, bit_pos);
131
51.9k
  config->filter_sharpness = Extract(7, data, size, bit_pos);
132
51.9k
  config->filter_type = Extract(1, data, size, bit_pos);
133
51.9k
  config->autofilter = Extract(1, data, size, bit_pos);
134
51.9k
  config->alpha_compression = Extract(1, data, size, bit_pos);
135
51.9k
  config->alpha_filtering = Extract(2, data, size, bit_pos);
136
51.9k
  config->alpha_quality = Extract(100, data, size, bit_pos);
137
51.9k
  config->pass = 1 + Extract(9, data, size, bit_pos);
138
51.9k
  config->show_compressed = 1;
139
51.9k
  config->preprocessing = Extract(2, data, size, bit_pos);
140
51.9k
  config->partitions = Extract(3, data, size, bit_pos);
141
51.9k
  config->partition_limit = 10 * Extract(10, data, size, bit_pos);
142
51.9k
  config->emulate_jpeg_size = Extract(1, data, size, bit_pos);
143
51.9k
  config->thread_level = Extract(1, data, size, bit_pos);
144
51.9k
  config->low_memory = Extract(1, data, size, bit_pos);
145
51.9k
  config->near_lossless = 20 * Extract(5, data, size, bit_pos);
146
51.9k
  config->exact = Extract(1, data, size, bit_pos);
147
51.9k
  config->use_delta_palette = Extract(1, data, size, bit_pos);
148
51.9k
  config->use_sharp_yuv = Extract(1, data, size, bit_pos);
149
51.9k
  return WebPValidateConfig(config);
150
51.9k
}
enc_dec_fuzzer.cc:ExtractWebPConfig(WebPConfig*, unsigned char const*, unsigned long, unsigned int*)
Line
Count
Source
121
4.79k
                                         uint32_t* const bit_pos) {
122
4.79k
  if (config == NULL || !WebPConfigInit(config)) return 0;
123
4.79k
  config->lossless = Extract(1, data, size, bit_pos);
124
4.79k
  config->quality = Extract(100, data, size, bit_pos);
125
4.79k
  config->method = Extract(6, data, size, bit_pos);
126
4.79k
  config->image_hint =
127
4.79k
      (WebPImageHint)Extract(WEBP_HINT_LAST - 1, data, size, bit_pos);
128
4.79k
  config->segments = 1 + Extract(3, data, size, bit_pos);
129
4.79k
  config->sns_strength = Extract(100, data, size, bit_pos);
130
4.79k
  config->filter_strength = Extract(100, data, size, bit_pos);
131
4.79k
  config->filter_sharpness = Extract(7, data, size, bit_pos);
132
4.79k
  config->filter_type = Extract(1, data, size, bit_pos);
133
4.79k
  config->autofilter = Extract(1, data, size, bit_pos);
134
4.79k
  config->alpha_compression = Extract(1, data, size, bit_pos);
135
4.79k
  config->alpha_filtering = Extract(2, data, size, bit_pos);
136
4.79k
  config->alpha_quality = Extract(100, data, size, bit_pos);
137
4.79k
  config->pass = 1 + Extract(9, data, size, bit_pos);
138
4.79k
  config->show_compressed = 1;
139
4.79k
  config->preprocessing = Extract(2, data, size, bit_pos);
140
4.79k
  config->partitions = Extract(3, data, size, bit_pos);
141
4.79k
  config->partition_limit = 10 * Extract(10, data, size, bit_pos);
142
4.79k
  config->emulate_jpeg_size = Extract(1, data, size, bit_pos);
143
4.79k
  config->thread_level = Extract(1, data, size, bit_pos);
144
4.79k
  config->low_memory = Extract(1, data, size, bit_pos);
145
4.79k
  config->near_lossless = 20 * Extract(5, data, size, bit_pos);
146
4.79k
  config->exact = Extract(1, data, size, bit_pos);
147
4.79k
  config->use_delta_palette = Extract(1, data, size, bit_pos);
148
4.79k
  config->use_sharp_yuv = Extract(1, data, size, bit_pos);
149
4.79k
  return WebPValidateConfig(config);
150
4.79k
}
Unexecuted instantiation: simple_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.1k
                                         uint32_t* const bit_pos) {
122
47.1k
  if (config == NULL || !WebPConfigInit(config)) return 0;
123
47.1k
  config->lossless = Extract(1, data, size, bit_pos);
124
47.1k
  config->quality = Extract(100, data, size, bit_pos);
125
47.1k
  config->method = Extract(6, data, size, bit_pos);
126
47.1k
  config->image_hint =
127
47.1k
      (WebPImageHint)Extract(WEBP_HINT_LAST - 1, data, size, bit_pos);
128
47.1k
  config->segments = 1 + Extract(3, data, size, bit_pos);
129
47.1k
  config->sns_strength = Extract(100, data, size, bit_pos);
130
47.1k
  config->filter_strength = Extract(100, data, size, bit_pos);
131
47.1k
  config->filter_sharpness = Extract(7, data, size, bit_pos);
132
47.1k
  config->filter_type = Extract(1, data, size, bit_pos);
133
47.1k
  config->autofilter = Extract(1, data, size, bit_pos);
134
47.1k
  config->alpha_compression = Extract(1, data, size, bit_pos);
135
47.1k
  config->alpha_filtering = Extract(2, data, size, bit_pos);
136
47.1k
  config->alpha_quality = Extract(100, data, size, bit_pos);
137
47.1k
  config->pass = 1 + Extract(9, data, size, bit_pos);
138
47.1k
  config->show_compressed = 1;
139
47.1k
  config->preprocessing = Extract(2, data, size, bit_pos);
140
47.1k
  config->partitions = Extract(3, data, size, bit_pos);
141
47.1k
  config->partition_limit = 10 * Extract(10, data, size, bit_pos);
142
47.1k
  config->emulate_jpeg_size = Extract(1, data, size, bit_pos);
143
47.1k
  config->thread_level = Extract(1, data, size, bit_pos);
144
47.1k
  config->low_memory = Extract(1, data, size, bit_pos);
145
47.1k
  config->near_lossless = 20 * Extract(5, data, size, bit_pos);
146
47.1k
  config->exact = Extract(1, data, size, bit_pos);
147
47.1k
  config->use_delta_palette = Extract(1, data, size, bit_pos);
148
47.1k
  config->use_sharp_yuv = Extract(1, data, size, bit_pos);
149
47.1k
  return WebPValidateConfig(config);
150
47.1k
}
Unexecuted instantiation: animation_api_fuzzer.c:ExtractWebPConfig
Unexecuted instantiation: advanced_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.9k
                                            uint32_t* const bit_pos) {
157
51.9k
  if (pic == NULL) return 0;
158
159
  // Pick a source picture.
160
51.9k
  const uint8_t* kImagesData[] = {
161
51.9k
      kImgAlphaData,
162
51.9k
      kImgGridData,
163
51.9k
      kImgPeakData
164
51.9k
  };
165
51.9k
  const int kImagesWidth[] = {
166
51.9k
      kImgAlphaWidth,
167
51.9k
      kImgGridWidth,
168
51.9k
      kImgPeakWidth
169
51.9k
  };
170
51.9k
  const int kImagesHeight[] = {
171
51.9k
      kImgAlphaHeight,
172
51.9k
      kImgGridHeight,
173
51.9k
      kImgPeakHeight
174
51.9k
  };
175
51.9k
  const size_t kNbImages = sizeof(kImagesData) / sizeof(kImagesData[0]);
176
51.9k
  const size_t image_index = Extract(kNbImages - 1, data, size, bit_pos);
177
51.9k
  const uint8_t* const image_data = kImagesData[image_index];
178
51.9k
  pic->width = kImagesWidth[image_index];
179
51.9k
  pic->height = kImagesHeight[image_index];
180
51.9k
  pic->argb_stride = pic->width * 4 * sizeof(uint8_t);
181
182
  // Read the bytes.
183
51.9k
  return WebPPictureImportRGBA(pic, image_data, pic->argb_stride);
184
51.9k
}
enc_dec_fuzzer.cc:ExtractSourcePicture(WebPPicture*, unsigned char const*, unsigned long, unsigned int*)
Line
Count
Source
156
4.79k
                                            uint32_t* const bit_pos) {
157
4.79k
  if (pic == NULL) return 0;
158
159
  // Pick a source picture.
160
4.79k
  const uint8_t* kImagesData[] = {
161
4.79k
      kImgAlphaData,
162
4.79k
      kImgGridData,
163
4.79k
      kImgPeakData
164
4.79k
  };
165
4.79k
  const int kImagesWidth[] = {
166
4.79k
      kImgAlphaWidth,
167
4.79k
      kImgGridWidth,
168
4.79k
      kImgPeakWidth
169
4.79k
  };
170
4.79k
  const int kImagesHeight[] = {
171
4.79k
      kImgAlphaHeight,
172
4.79k
      kImgGridHeight,
173
4.79k
      kImgPeakHeight
174
4.79k
  };
175
4.79k
  const size_t kNbImages = sizeof(kImagesData) / sizeof(kImagesData[0]);
176
4.79k
  const size_t image_index = Extract(kNbImages - 1, data, size, bit_pos);
177
4.79k
  const uint8_t* const image_data = kImagesData[image_index];
178
4.79k
  pic->width = kImagesWidth[image_index];
179
4.79k
  pic->height = kImagesHeight[image_index];
180
4.79k
  pic->argb_stride = pic->width * 4 * sizeof(uint8_t);
181
182
  // Read the bytes.
183
4.79k
  return WebPPictureImportRGBA(pic, image_data, pic->argb_stride);
184
4.79k
}
Unexecuted instantiation: simple_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.1k
                                            uint32_t* const bit_pos) {
157
47.1k
  if (pic == NULL) return 0;
158
159
  // Pick a source picture.
160
47.1k
  const uint8_t* kImagesData[] = {
161
47.1k
      kImgAlphaData,
162
47.1k
      kImgGridData,
163
47.1k
      kImgPeakData
164
47.1k
  };
165
47.1k
  const int kImagesWidth[] = {
166
47.1k
      kImgAlphaWidth,
167
47.1k
      kImgGridWidth,
168
47.1k
      kImgPeakWidth
169
47.1k
  };
170
47.1k
  const int kImagesHeight[] = {
171
47.1k
      kImgAlphaHeight,
172
47.1k
      kImgGridHeight,
173
47.1k
      kImgPeakHeight
174
47.1k
  };
175
47.1k
  const size_t kNbImages = sizeof(kImagesData) / sizeof(kImagesData[0]);
176
47.1k
  const size_t image_index = Extract(kNbImages - 1, data, size, bit_pos);
177
47.1k
  const uint8_t* const image_data = kImagesData[image_index];
178
47.1k
  pic->width = kImagesWidth[image_index];
179
47.1k
  pic->height = kImagesHeight[image_index];
180
47.1k
  pic->argb_stride = pic->width * 4 * sizeof(uint8_t);
181
182
  // Read the bytes.
183
47.1k
  return WebPPictureImportRGBA(pic, image_data, pic->argb_stride);
184
47.1k
}
Unexecuted instantiation: animation_api_fuzzer.c:ExtractSourcePicture
Unexecuted instantiation: advanced_api_fuzzer.c:ExtractSourcePicture
185
186
//------------------------------------------------------------------------------
187
188
5.95k
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.71k
static WEBP_INLINE int Max(int a, int b) { return ((a < b) ? b : a); }
Unexecuted instantiation: simple_api_fuzzer.c:Max
Unexecuted instantiation: mux_demux_api_fuzzer.c:Max
animencoder_fuzzer.cc:Max(int, int)
Line
Count
Source
188
2.56k
static WEBP_INLINE int Max(int a, int b) { return ((a < b) ? b : a); }
Unexecuted instantiation: animation_api_fuzzer.c:Max
advanced_api_fuzzer.c:Max
Line
Count
Source
188
672
static WEBP_INLINE int Max(int a, int b) { return ((a < b) ? b : a); }
189
190
static WEBP_INLINE int ExtractAndCropOrScale(WebPPicture* const pic,
191
                                             const uint8_t data[], size_t size,
192
9.49k
                                             uint32_t* const bit_pos) {
193
9.49k
  if (pic == NULL) return 0;
194
9.49k
#if !defined(WEBP_REDUCE_SIZE)
195
9.49k
  const int alter_input = Extract(1, data, size, bit_pos);
196
9.49k
  const int crop_or_scale = Extract(1, data, size, bit_pos);
197
9.49k
  const int width_ratio = 1 + Extract(7, data, size, bit_pos);
198
9.49k
  const int height_ratio = 1 + Extract(7, data, size, bit_pos);
199
9.49k
  if (alter_input) {
200
7.99k
    if (crop_or_scale) {
201
2.64k
      const uint32_t left_ratio = 1 + Extract(7, data, size, bit_pos);
202
2.64k
      const uint32_t top_ratio = 1 + Extract(7, data, size, bit_pos);
203
2.64k
      const int cropped_width = Max(1, pic->width / width_ratio);
204
2.64k
      const int cropped_height = Max(1, pic->height / height_ratio);
205
2.64k
      const int cropped_left = (pic->width - cropped_width) / left_ratio;
206
2.64k
      const int cropped_top = (pic->height - cropped_height) / top_ratio;
207
2.64k
      return WebPPictureCrop(pic, cropped_left, cropped_top, cropped_width,
208
2.64k
                             cropped_height);
209
5.35k
    } else {
210
5.35k
      const int scaled_width = 1 + (pic->width * width_ratio) / 8;
211
5.35k
      const int scaled_height = 1 + (pic->height * height_ratio) / 8;
212
5.35k
      return WebPPictureRescale(pic, scaled_width, scaled_height);
213
5.35k
    }
214
7.99k
  }
215
#else   // defined(WEBP_REDUCE_SIZE)
216
  (void)data;
217
  (void)size;
218
  (void)bit_pos;
219
#endif  // !defined(WEBP_REDUCE_SIZE)
220
1.49k
  return 1;
221
9.49k
}
enc_dec_fuzzer.cc:ExtractAndCropOrScale(WebPPicture*, unsigned char const*, unsigned long, unsigned int*)
Line
Count
Source
192
4.79k
                                             uint32_t* const bit_pos) {
193
4.79k
  if (pic == NULL) return 0;
194
4.79k
#if !defined(WEBP_REDUCE_SIZE)
195
4.79k
  const int alter_input = Extract(1, data, size, bit_pos);
196
4.79k
  const int crop_or_scale = Extract(1, data, size, bit_pos);
197
4.79k
  const int width_ratio = 1 + Extract(7, data, size, bit_pos);
198
4.79k
  const int height_ratio = 1 + Extract(7, data, size, bit_pos);
199
4.79k
  if (alter_input) {
200
4.16k
    if (crop_or_scale) {
201
1.35k
      const uint32_t left_ratio = 1 + Extract(7, data, size, bit_pos);
202
1.35k
      const uint32_t top_ratio = 1 + Extract(7, data, size, bit_pos);
203
1.35k
      const int cropped_width = Max(1, pic->width / width_ratio);
204
1.35k
      const int cropped_height = Max(1, pic->height / height_ratio);
205
1.35k
      const int cropped_left = (pic->width - cropped_width) / left_ratio;
206
1.35k
      const int cropped_top = (pic->height - cropped_height) / top_ratio;
207
1.35k
      return WebPPictureCrop(pic, cropped_left, cropped_top, cropped_width,
208
1.35k
                             cropped_height);
209
2.80k
    } else {
210
2.80k
      const int scaled_width = 1 + (pic->width * width_ratio) / 8;
211
2.80k
      const int scaled_height = 1 + (pic->height * height_ratio) / 8;
212
2.80k
      return WebPPictureRescale(pic, scaled_width, scaled_height);
213
2.80k
    }
214
4.16k
  }
215
#else   // defined(WEBP_REDUCE_SIZE)
216
  (void)data;
217
  (void)size;
218
  (void)bit_pos;
219
#endif  // !defined(WEBP_REDUCE_SIZE)
220
637
  return 1;
221
4.79k
}
Unexecuted instantiation: simple_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.69k
                                             uint32_t* const bit_pos) {
193
4.69k
  if (pic == NULL) return 0;
194
4.69k
#if !defined(WEBP_REDUCE_SIZE)
195
4.69k
  const int alter_input = Extract(1, data, size, bit_pos);
196
4.69k
  const int crop_or_scale = Extract(1, data, size, bit_pos);
197
4.69k
  const int width_ratio = 1 + Extract(7, data, size, bit_pos);
198
4.69k
  const int height_ratio = 1 + Extract(7, data, size, bit_pos);
199
4.69k
  if (alter_input) {
200
3.83k
    if (crop_or_scale) {
201
1.28k
      const uint32_t left_ratio = 1 + Extract(7, data, size, bit_pos);
202
1.28k
      const uint32_t top_ratio = 1 + Extract(7, data, size, bit_pos);
203
1.28k
      const int cropped_width = Max(1, pic->width / width_ratio);
204
1.28k
      const int cropped_height = Max(1, pic->height / height_ratio);
205
1.28k
      const int cropped_left = (pic->width - cropped_width) / left_ratio;
206
1.28k
      const int cropped_top = (pic->height - cropped_height) / top_ratio;
207
1.28k
      return WebPPictureCrop(pic, cropped_left, cropped_top, cropped_width,
208
1.28k
                             cropped_height);
209
2.54k
    } else {
210
2.54k
      const int scaled_width = 1 + (pic->width * width_ratio) / 8;
211
2.54k
      const int scaled_height = 1 + (pic->height * height_ratio) / 8;
212
2.54k
      return WebPPictureRescale(pic, scaled_width, scaled_height);
213
2.54k
    }
214
3.83k
  }
215
#else   // defined(WEBP_REDUCE_SIZE)
216
  (void)data;
217
  (void)size;
218
  (void)bit_pos;
219
#endif  // !defined(WEBP_REDUCE_SIZE)
220
861
  return 1;
221
4.69k
}
Unexecuted instantiation: animation_api_fuzzer.c:ExtractAndCropOrScale
Unexecuted instantiation: advanced_api_fuzzer.c:ExtractAndCropOrScale
222
223
#endif  // WEBP_TESTS_FUZZER_FUZZ_UTILS_H_