Coverage Report

Created: 2018-12-03 14:26

/src/fuzz.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
#include <stdint.h>
18
#include <stdlib.h>
19
20
#include "dsp/dsp.h"
21
#include "img_alpha.h"
22
#include "img_grid.h"
23
#include "img_peak.h"
24
#include "webp/encode.h"
25
26
//------------------------------------------------------------------------------
27
// Arbitrary limits to prevent OOM, timeout, or slow execution.
28
//
29
// The decoded image size, and for animations additionally the canvas size.
30
static const size_t kFuzzPxLimit = 1024 * 1024;
31
// Demuxed or decoded animation frames.
32
static const int kFuzzFrameLimit = 3;
33
34
// Reads and sums (up to) 128 spread-out bytes.
35
8.07k
uint8_t FuzzHash(const uint8_t* const data, size_t size) {
36
8.07k
  uint8_t value = 0;
37
8.07k
  size_t incr = size / 128;
38
8.07k
  if (!incr) incr = 1;
39
445k
  for (size_t i = 0; i < size; i += incr) value += data[i];
40
8.07k
  return value;
41
8.07k
}
FuzzHash
Line
Count
Source
35
8.07k
uint8_t FuzzHash(const uint8_t* const data, size_t size) {
36
8.07k
  uint8_t value = 0;
37
8.07k
  size_t incr = size / 128;
38
8.07k
  if (!incr) incr = 1;
39
445k
  for (size_t i = 0; i < size; i += incr) value += data[i];
40
8.07k
  return value;
41
8.07k
}
Unexecuted instantiation: FuzzHash(unsigned char const*, unsigned long)
42
43
//------------------------------------------------------------------------------
44
// Extract an integer in [0, max_value].
45
46
static uint32_t Extract(uint32_t max_value, const uint8_t data[], size_t size,
47
1.08M
                        uint32_t* const bit_pos) {
48
1.08M
  uint32_t v = 0;
49
1.08M
  int range = 1;
50
2.08M
  while (*bit_pos < 8 * size && range <= max_value) {
51
1.00M
    const uint8_t mask = 1u << (*bit_pos & 7);
52
1.00M
    v = (v << 1) | !!(data[*bit_pos >> 3] & mask);
53
1.00M
    range <<= 1;
54
1.00M
    ++*bit_pos;
55
1.00M
  }
56
1.08M
  return v % (max_value + 1);
57
1.08M
}
Unexecuted instantiation: fuzz_animation_api.c:Extract
Unexecuted instantiation: fuzz_demux_api.c:Extract
Unexecuted instantiation: fuzz_advanced_api.c:Extract
fuzz_webp_animencoder.cc:Extract(unsigned int, unsigned char const*, unsigned long, unsigned int*)
Line
Count
Source
47
999k
                        uint32_t* const bit_pos) {
48
999k
  uint32_t v = 0;
49
999k
  int range = 1;
50
1.87M
  while (*bit_pos < 8 * size && range <= max_value) {
51
878k
    const uint8_t mask = 1u << (*bit_pos & 7);
52
878k
    v = (v << 1) | !!(data[*bit_pos >> 3] & mask);
53
878k
    range <<= 1;
54
878k
    ++*bit_pos;
55
878k
  }
56
999k
  return v % (max_value + 1);
57
999k
}
fuzz_webp_enc_dec.cc:Extract(unsigned int, unsigned char const*, unsigned long, unsigned int*)
Line
Count
Source
47
82.6k
                        uint32_t* const bit_pos) {
48
82.6k
  uint32_t v = 0;
49
82.6k
  int range = 1;
50
206k
  while (*bit_pos < 8 * size && range <= max_value) {
51
123k
    const uint8_t mask = 1u << (*bit_pos & 7);
52
123k
    v = (v << 1) | !!(data[*bit_pos >> 3] & mask);
53
123k
    range <<= 1;
54
123k
    ++*bit_pos;
55
123k
  }
56
82.6k
  return v % (max_value + 1);
57
82.6k
}
Unexecuted instantiation: fuzz_simple_api.c:Extract
58
59
//------------------------------------------------------------------------------
60
// Some functions to override VP8GetCPUInfo and disable some optimizations.
61
62
static VP8CPUInfo GetCPUInfo;
63
64
17.1k
static int GetCPUInfoNoSSE41(CPUFeature feature) {
65
17.1k
  if (feature == kSSE4_1 || feature == kAVX) return 0;
66
10.6k
  return GetCPUInfo(feature);
67
10.6k
}
Unexecuted instantiation: fuzz_animation_api.c:GetCPUInfoNoSSE41
Unexecuted instantiation: fuzz_demux_api.c:GetCPUInfoNoSSE41
Unexecuted instantiation: fuzz_advanced_api.c:GetCPUInfoNoSSE41
fuzz_webp_animencoder.cc:GetCPUInfoNoSSE41(CPUFeature)
Line
Count
Source
64
11.1k
static int GetCPUInfoNoSSE41(CPUFeature feature) {
65
11.1k
  if (feature == kSSE4_1 || feature == kAVX) return 0;
66
7.06k
  return GetCPUInfo(feature);
67
7.06k
}
fuzz_webp_enc_dec.cc:GetCPUInfoNoSSE41(CPUFeature)
Line
Count
Source
64
6.01k
static int GetCPUInfoNoSSE41(CPUFeature feature) {
65
6.01k
  if (feature == kSSE4_1 || feature == kAVX) return 0;
66
3.61k
  return GetCPUInfo(feature);
67
3.61k
}
Unexecuted instantiation: fuzz_simple_api.c:GetCPUInfoNoSSE41
68
69
7.78k
static int GetCPUInfoNoAVX(CPUFeature feature) {
70
7.78k
  if (feature == kAVX) return 0;
71
7.78k
  return GetCPUInfo(feature);
72
7.78k
}
Unexecuted instantiation: fuzz_animation_api.c:GetCPUInfoNoAVX
Unexecuted instantiation: fuzz_demux_api.c:GetCPUInfoNoAVX
Unexecuted instantiation: fuzz_advanced_api.c:GetCPUInfoNoAVX
fuzz_webp_animencoder.cc:GetCPUInfoNoAVX(CPUFeature)
Line
Count
Source
69
4.46k
static int GetCPUInfoNoAVX(CPUFeature feature) {
70
4.46k
  if (feature == kAVX) return 0;
71
4.46k
  return GetCPUInfo(feature);
72
4.46k
}
fuzz_webp_enc_dec.cc:GetCPUInfoNoAVX(CPUFeature)
Line
Count
Source
69
3.31k
static int GetCPUInfoNoAVX(CPUFeature feature) {
70
3.31k
  if (feature == kAVX) return 0;
71
3.31k
  return GetCPUInfo(feature);
72
3.31k
}
Unexecuted instantiation: fuzz_simple_api.c:GetCPUInfoNoAVX
73
74
11.9k
static int GetCPUInfoForceSlowSSSE3(CPUFeature feature) {
75
11.9k
  if (feature == kSlowSSSE3 && GetCPUInfo(kSSE3)) {
76
0
    return 1;  // we have SSE3 -> force SlowSSSE3
77
0
  }
78
11.9k
  return GetCPUInfo(feature);
79
11.9k
}
Unexecuted instantiation: fuzz_animation_api.c:GetCPUInfoForceSlowSSSE3
Unexecuted instantiation: fuzz_demux_api.c:GetCPUInfoForceSlowSSSE3
Unexecuted instantiation: fuzz_advanced_api.c:GetCPUInfoForceSlowSSSE3
fuzz_webp_animencoder.cc:GetCPUInfoForceSlowSSSE3(CPUFeature)
Line
Count
Source
74
7.52k
static int GetCPUInfoForceSlowSSSE3(CPUFeature feature) {
75
7.52k
  if (feature == kSlowSSSE3 && GetCPUInfo(kSSE3)) {
76
0
    return 1;  // we have SSE3 -> force SlowSSSE3
77
0
  }
78
7.52k
  return GetCPUInfo(feature);
79
7.52k
}
fuzz_webp_enc_dec.cc:GetCPUInfoForceSlowSSSE3(CPUFeature)
Line
Count
Source
74
4.42k
static int GetCPUInfoForceSlowSSSE3(CPUFeature feature) {
75
4.42k
  if (feature == kSlowSSSE3 && GetCPUInfo(kSSE3)) {
76
0
    return 1;  // we have SSE3 -> force SlowSSSE3
77
0
  }
78
4.42k
  return GetCPUInfo(feature);
79
4.42k
}
Unexecuted instantiation: fuzz_simple_api.c:GetCPUInfoForceSlowSSSE3
80
81
14.0k
static int GetCPUInfoOnlyC(CPUFeature feature) { return 0; }
Unexecuted instantiation: fuzz_animation_api.c:GetCPUInfoOnlyC
Unexecuted instantiation: fuzz_demux_api.c:GetCPUInfoOnlyC
Unexecuted instantiation: fuzz_advanced_api.c:GetCPUInfoOnlyC
fuzz_webp_animencoder.cc:GetCPUInfoOnlyC(CPUFeature)
Line
Count
Source
81
8.36k
static int GetCPUInfoOnlyC(CPUFeature feature) { return 0; }
fuzz_webp_enc_dec.cc:GetCPUInfoOnlyC(CPUFeature)
Line
Count
Source
81
5.66k
static int GetCPUInfoOnlyC(CPUFeature feature) { return 0; }
Unexecuted instantiation: fuzz_simple_api.c:GetCPUInfoOnlyC
82
83
static void ExtractAndDisableOptimizations(VP8CPUInfo default_VP8GetCPUInfo,
84
                                           const uint8_t data[], size_t size,
85
6.06k
                                           uint32_t* const bit_pos) {
86
6.06k
  GetCPUInfo = default_VP8GetCPUInfo;
87
6.06k
  const VP8CPUInfo kVP8CPUInfos[5] = {GetCPUInfoOnlyC, GetCPUInfoForceSlowSSSE3,
88
6.06k
                                      GetCPUInfoNoSSE41, GetCPUInfoNoAVX,
89
6.06k
                                      GetCPUInfo};
90
6.06k
  int VP8GetCPUInfo_index = Extract(4, data, size, bit_pos);
91
6.06k
  VP8GetCPUInfo = kVP8CPUInfos[VP8GetCPUInfo_index];
92
6.06k
}
Unexecuted instantiation: fuzz_animation_api.c:ExtractAndDisableOptimizations
Unexecuted instantiation: fuzz_demux_api.c:ExtractAndDisableOptimizations
Unexecuted instantiation: fuzz_advanced_api.c:ExtractAndDisableOptimizations
fuzz_webp_animencoder.cc:ExtractAndDisableOptimizations(int (*)(CPUFeature), unsigned char const*, unsigned long, unsigned int*)
Line
Count
Source
85
3.44k
                                           uint32_t* const bit_pos) {
86
3.44k
  GetCPUInfo = default_VP8GetCPUInfo;
87
3.44k
  const VP8CPUInfo kVP8CPUInfos[5] = {GetCPUInfoOnlyC, GetCPUInfoForceSlowSSSE3,
88
3.44k
                                      GetCPUInfoNoSSE41, GetCPUInfoNoAVX,
89
3.44k
                                      GetCPUInfo};
90
3.44k
  int VP8GetCPUInfo_index = Extract(4, data, size, bit_pos);
91
3.44k
  VP8GetCPUInfo = kVP8CPUInfos[VP8GetCPUInfo_index];
92
3.44k
}
fuzz_webp_enc_dec.cc:ExtractAndDisableOptimizations(int (*)(CPUFeature), unsigned char const*, unsigned long, unsigned int*)
Line
Count
Source
85
2.61k
                                           uint32_t* const bit_pos) {
86
2.61k
  GetCPUInfo = default_VP8GetCPUInfo;
87
2.61k
  const VP8CPUInfo kVP8CPUInfos[5] = {GetCPUInfoOnlyC, GetCPUInfoForceSlowSSSE3,
88
2.61k
                                      GetCPUInfoNoSSE41, GetCPUInfoNoAVX,
89
2.61k
                                      GetCPUInfo};
90
2.61k
  int VP8GetCPUInfo_index = Extract(4, data, size, bit_pos);
91
2.61k
  VP8GetCPUInfo = kVP8CPUInfos[VP8GetCPUInfo_index];
92
2.61k
}
Unexecuted instantiation: fuzz_simple_api.c:ExtractAndDisableOptimizations
93
94
//------------------------------------------------------------------------------
95
96
static int ExtractWebPConfig(WebPConfig* const config, const uint8_t data[],
97
37.0k
                             size_t size, uint32_t* const bit_pos) {
98
37.0k
  if (config == NULL || !WebPConfigInit(config)) return 0;
99
37.0k
  config->lossless = Extract(1, data, size, bit_pos);
100
37.0k
  config->quality = Extract(100, data, size, bit_pos);
101
37.0k
  config->method = Extract(6, data, size, bit_pos);
102
37.0k
  config->image_hint =
103
37.0k
      (WebPImageHint)Extract(WEBP_HINT_LAST - 1, data, size, bit_pos);
104
37.0k
  config->segments = 1 + Extract(3, data, size, bit_pos);
105
37.0k
  config->sns_strength = Extract(100, data, size, bit_pos);
106
37.0k
  config->filter_strength = Extract(100, data, size, bit_pos);
107
37.0k
  config->filter_sharpness = Extract(7, data, size, bit_pos);
108
37.0k
  config->filter_type = Extract(1, data, size, bit_pos);
109
37.0k
  config->autofilter = Extract(1, data, size, bit_pos);
110
37.0k
  config->alpha_compression = Extract(1, data, size, bit_pos);
111
37.0k
  config->alpha_filtering = Extract(2, data, size, bit_pos);
112
37.0k
  config->alpha_quality = Extract(100, data, size, bit_pos);
113
37.0k
  config->pass = 1 + Extract(9, data, size, bit_pos);
114
37.0k
  config->show_compressed = 1;
115
37.0k
  config->preprocessing = Extract(2, data, size, bit_pos);
116
37.0k
  config->partitions = Extract(3, data, size, bit_pos);
117
37.0k
  config->partition_limit = 10 * Extract(10, data, size, bit_pos);
118
37.0k
  config->emulate_jpeg_size = Extract(1, data, size, bit_pos);
119
37.0k
  config->thread_level = Extract(1, data, size, bit_pos);
120
37.0k
  config->low_memory = Extract(1, data, size, bit_pos);
121
37.0k
  config->near_lossless = 20 * Extract(5, data, size, bit_pos);
122
37.0k
  config->exact = Extract(1, data, size, bit_pos);
123
37.0k
  config->use_delta_palette = Extract(1, data, size, bit_pos);
124
37.0k
  config->use_sharp_yuv = Extract(1, data, size, bit_pos);
125
37.0k
  return WebPValidateConfig(config);
126
37.0k
}
Unexecuted instantiation: fuzz_animation_api.c:ExtractWebPConfig
Unexecuted instantiation: fuzz_demux_api.c:ExtractWebPConfig
Unexecuted instantiation: fuzz_advanced_api.c:ExtractWebPConfig
fuzz_webp_animencoder.cc:ExtractWebPConfig(WebPConfig*, unsigned char const*, unsigned long, unsigned int*)
Line
Count
Source
97
34.4k
                             size_t size, uint32_t* const bit_pos) {
98
34.4k
  if (config == NULL || !WebPConfigInit(config)) return 0;
99
34.4k
  config->lossless = Extract(1, data, size, bit_pos);
100
34.4k
  config->quality = Extract(100, data, size, bit_pos);
101
34.4k
  config->method = Extract(6, data, size, bit_pos);
102
34.4k
  config->image_hint =
103
34.4k
      (WebPImageHint)Extract(WEBP_HINT_LAST - 1, data, size, bit_pos);
104
34.4k
  config->segments = 1 + Extract(3, data, size, bit_pos);
105
34.4k
  config->sns_strength = Extract(100, data, size, bit_pos);
106
34.4k
  config->filter_strength = Extract(100, data, size, bit_pos);
107
34.4k
  config->filter_sharpness = Extract(7, data, size, bit_pos);
108
34.4k
  config->filter_type = Extract(1, data, size, bit_pos);
109
34.4k
  config->autofilter = Extract(1, data, size, bit_pos);
110
34.4k
  config->alpha_compression = Extract(1, data, size, bit_pos);
111
34.4k
  config->alpha_filtering = Extract(2, data, size, bit_pos);
112
34.4k
  config->alpha_quality = Extract(100, data, size, bit_pos);
113
34.4k
  config->pass = 1 + Extract(9, data, size, bit_pos);
114
34.4k
  config->show_compressed = 1;
115
34.4k
  config->preprocessing = Extract(2, data, size, bit_pos);
116
34.4k
  config->partitions = Extract(3, data, size, bit_pos);
117
34.4k
  config->partition_limit = 10 * Extract(10, data, size, bit_pos);
118
34.4k
  config->emulate_jpeg_size = Extract(1, data, size, bit_pos);
119
34.4k
  config->thread_level = Extract(1, data, size, bit_pos);
120
34.4k
  config->low_memory = Extract(1, data, size, bit_pos);
121
34.4k
  config->near_lossless = 20 * Extract(5, data, size, bit_pos);
122
34.4k
  config->exact = Extract(1, data, size, bit_pos);
123
34.4k
  config->use_delta_palette = Extract(1, data, size, bit_pos);
124
34.4k
  config->use_sharp_yuv = Extract(1, data, size, bit_pos);
125
34.4k
  return WebPValidateConfig(config);
126
34.4k
}
fuzz_webp_enc_dec.cc:ExtractWebPConfig(WebPConfig*, unsigned char const*, unsigned long, unsigned int*)
Line
Count
Source
97
2.61k
                             size_t size, uint32_t* const bit_pos) {
98
2.61k
  if (config == NULL || !WebPConfigInit(config)) return 0;
99
2.61k
  config->lossless = Extract(1, data, size, bit_pos);
100
2.61k
  config->quality = Extract(100, data, size, bit_pos);
101
2.61k
  config->method = Extract(6, data, size, bit_pos);
102
2.61k
  config->image_hint =
103
2.61k
      (WebPImageHint)Extract(WEBP_HINT_LAST - 1, data, size, bit_pos);
104
2.61k
  config->segments = 1 + Extract(3, data, size, bit_pos);
105
2.61k
  config->sns_strength = Extract(100, data, size, bit_pos);
106
2.61k
  config->filter_strength = Extract(100, data, size, bit_pos);
107
2.61k
  config->filter_sharpness = Extract(7, data, size, bit_pos);
108
2.61k
  config->filter_type = Extract(1, data, size, bit_pos);
109
2.61k
  config->autofilter = Extract(1, data, size, bit_pos);
110
2.61k
  config->alpha_compression = Extract(1, data, size, bit_pos);
111
2.61k
  config->alpha_filtering = Extract(2, data, size, bit_pos);
112
2.61k
  config->alpha_quality = Extract(100, data, size, bit_pos);
113
2.61k
  config->pass = 1 + Extract(9, data, size, bit_pos);
114
2.61k
  config->show_compressed = 1;
115
2.61k
  config->preprocessing = Extract(2, data, size, bit_pos);
116
2.61k
  config->partitions = Extract(3, data, size, bit_pos);
117
2.61k
  config->partition_limit = 10 * Extract(10, data, size, bit_pos);
118
2.61k
  config->emulate_jpeg_size = Extract(1, data, size, bit_pos);
119
2.61k
  config->thread_level = Extract(1, data, size, bit_pos);
120
2.61k
  config->low_memory = Extract(1, data, size, bit_pos);
121
2.61k
  config->near_lossless = 20 * Extract(5, data, size, bit_pos);
122
2.61k
  config->exact = Extract(1, data, size, bit_pos);
123
2.61k
  config->use_delta_palette = Extract(1, data, size, bit_pos);
124
2.61k
  config->use_sharp_yuv = Extract(1, data, size, bit_pos);
125
2.61k
  return WebPValidateConfig(config);
126
2.61k
}
Unexecuted instantiation: fuzz_simple_api.c:ExtractWebPConfig
127
128
//------------------------------------------------------------------------------
129
130
static int ExtractSourcePicture(WebPPicture* const pic,
131
                                const uint8_t data[], size_t size,
132
37.0k
                                uint32_t* const bit_pos) {
133
37.0k
  if (pic == NULL) return 0;
134
37.0k
135
37.0k
  // Pick a source picture.
136
37.0k
  const uint8_t* kImagesData[] = {
137
37.0k
      kImgAlphaData,
138
37.0k
      kImgGridData,
139
37.0k
      kImgPeakData
140
37.0k
  };
141
37.0k
  const int kImagesWidth[] = {
142
37.0k
      kImgAlphaWidth,
143
37.0k
      kImgGridWidth,
144
37.0k
      kImgPeakWidth
145
37.0k
  };
146
37.0k
  const int kImagesHeight[] = {
147
37.0k
      kImgAlphaHeight,
148
37.0k
      kImgGridHeight,
149
37.0k
      kImgPeakHeight
150
37.0k
  };
151
37.0k
  const size_t kNbImages = sizeof(kImagesData) / sizeof(kImagesData[0]);
152
37.0k
  const size_t image_index = Extract(kNbImages - 1, data, size, bit_pos);
153
37.0k
  const uint8_t* const image_data = kImagesData[image_index];
154
37.0k
  pic->width = kImagesWidth[image_index];
155
37.0k
  pic->height = kImagesHeight[image_index];
156
37.0k
  pic->argb_stride = pic->width * 4 * sizeof(uint8_t);
157
37.0k
158
37.0k
  // Read the bytes.
159
37.0k
  return WebPPictureImportRGBA(pic, image_data, pic->argb_stride);
160
37.0k
}
Unexecuted instantiation: fuzz_animation_api.c:ExtractSourcePicture
Unexecuted instantiation: fuzz_demux_api.c:ExtractSourcePicture
Unexecuted instantiation: fuzz_advanced_api.c:ExtractSourcePicture
fuzz_webp_animencoder.cc:ExtractSourcePicture(WebPPicture*, unsigned char const*, unsigned long, unsigned int*)
Line
Count
Source
132
34.4k
                                uint32_t* const bit_pos) {
133
34.4k
  if (pic == NULL) return 0;
134
34.4k
135
34.4k
  // Pick a source picture.
136
34.4k
  const uint8_t* kImagesData[] = {
137
34.4k
      kImgAlphaData,
138
34.4k
      kImgGridData,
139
34.4k
      kImgPeakData
140
34.4k
  };
141
34.4k
  const int kImagesWidth[] = {
142
34.4k
      kImgAlphaWidth,
143
34.4k
      kImgGridWidth,
144
34.4k
      kImgPeakWidth
145
34.4k
  };
146
34.4k
  const int kImagesHeight[] = {
147
34.4k
      kImgAlphaHeight,
148
34.4k
      kImgGridHeight,
149
34.4k
      kImgPeakHeight
150
34.4k
  };
151
34.4k
  const size_t kNbImages = sizeof(kImagesData) / sizeof(kImagesData[0]);
152
34.4k
  const size_t image_index = Extract(kNbImages - 1, data, size, bit_pos);
153
34.4k
  const uint8_t* const image_data = kImagesData[image_index];
154
34.4k
  pic->width = kImagesWidth[image_index];
155
34.4k
  pic->height = kImagesHeight[image_index];
156
34.4k
  pic->argb_stride = pic->width * 4 * sizeof(uint8_t);
157
34.4k
158
34.4k
  // Read the bytes.
159
34.4k
  return WebPPictureImportRGBA(pic, image_data, pic->argb_stride);
160
34.4k
}
fuzz_webp_enc_dec.cc:ExtractSourcePicture(WebPPicture*, unsigned char const*, unsigned long, unsigned int*)
Line
Count
Source
132
2.61k
                                uint32_t* const bit_pos) {
133
2.61k
  if (pic == NULL) return 0;
134
2.61k
135
2.61k
  // Pick a source picture.
136
2.61k
  const uint8_t* kImagesData[] = {
137
2.61k
      kImgAlphaData,
138
2.61k
      kImgGridData,
139
2.61k
      kImgPeakData
140
2.61k
  };
141
2.61k
  const int kImagesWidth[] = {
142
2.61k
      kImgAlphaWidth,
143
2.61k
      kImgGridWidth,
144
2.61k
      kImgPeakWidth
145
2.61k
  };
146
2.61k
  const int kImagesHeight[] = {
147
2.61k
      kImgAlphaHeight,
148
2.61k
      kImgGridHeight,
149
2.61k
      kImgPeakHeight
150
2.61k
  };
151
2.61k
  const size_t kNbImages = sizeof(kImagesData) / sizeof(kImagesData[0]);
152
2.61k
  const size_t image_index = Extract(kNbImages - 1, data, size, bit_pos);
153
2.61k
  const uint8_t* const image_data = kImagesData[image_index];
154
2.61k
  pic->width = kImagesWidth[image_index];
155
2.61k
  pic->height = kImagesHeight[image_index];
156
2.61k
  pic->argb_stride = pic->width * 4 * sizeof(uint8_t);
157
2.61k
158
2.61k
  // Read the bytes.
159
2.61k
  return WebPPictureImportRGBA(pic, image_data, pic->argb_stride);
160
2.61k
}
Unexecuted instantiation: fuzz_simple_api.c:ExtractSourcePicture
161
162
//------------------------------------------------------------------------------
163
164
3.29k
static int max(int a, int b) { return ((a < b) ? b : a); }
Unexecuted instantiation: fuzz_animation_api.c:max
Unexecuted instantiation: fuzz_demux_api.c:max
Unexecuted instantiation: fuzz_advanced_api.c:max
fuzz_webp_animencoder.cc:max(int, int)
Line
Count
Source
164
1.81k
static int max(int a, int b) { return ((a < b) ? b : a); }
fuzz_webp_enc_dec.cc:max(int, int)
Line
Count
Source
164
1.47k
static int max(int a, int b) { return ((a < b) ? b : a); }
Unexecuted instantiation: fuzz_simple_api.c:max
165
166
static int ExtractAndCropOrScale(WebPPicture* const pic, const uint8_t data[],
167
6.06k
                                 size_t size, uint32_t* const bit_pos) {
168
6.06k
  if (pic == NULL) return 0;
169
6.06k
  const int alter_input = Extract(1, data, size, bit_pos);
170
6.06k
  const int crop_or_scale = Extract(1, data, size, bit_pos);
171
6.06k
  const int width_ratio = 1 + Extract(7, data, size, bit_pos);
172
6.06k
  const int height_ratio = 1 + Extract(7, data, size, bit_pos);
173
6.06k
  if (alter_input) {
174
4.76k
    if (crop_or_scale) {
175
1.64k
      const uint32_t left_ratio = 1 + Extract(7, data, size, bit_pos);
176
1.64k
      const uint32_t top_ratio = 1 + Extract(7, data, size, bit_pos);
177
1.64k
      const int cropped_width = max(1, pic->width / width_ratio);
178
1.64k
      const int cropped_height = max(1, pic->height / height_ratio);
179
1.64k
      const int cropped_left = (pic->width - cropped_width) / left_ratio;
180
1.64k
      const int cropped_top = (pic->height - cropped_height) / top_ratio;
181
1.64k
      return WebPPictureCrop(pic, cropped_left, cropped_top, cropped_width,
182
1.64k
                             cropped_height);
183
3.11k
    } else {
184
3.11k
      const int scaled_width = 1 + (pic->width * width_ratio) / 8;
185
3.11k
      const int scaled_height = 1 + (pic->height * height_ratio) / 8;
186
3.11k
      return WebPPictureRescale(pic, scaled_width, scaled_height);
187
3.11k
    }
188
1.30k
  }
189
1.30k
  return 1;
190
1.30k
}
Unexecuted instantiation: fuzz_animation_api.c:ExtractAndCropOrScale
Unexecuted instantiation: fuzz_demux_api.c:ExtractAndCropOrScale
Unexecuted instantiation: fuzz_advanced_api.c:ExtractAndCropOrScale
fuzz_webp_animencoder.cc:ExtractAndCropOrScale(WebPPicture*, unsigned char const*, unsigned long, unsigned int*)
Line
Count
Source
167
3.44k
                                 size_t size, uint32_t* const bit_pos) {
168
3.44k
  if (pic == NULL) return 0;
169
3.44k
  const int alter_input = Extract(1, data, size, bit_pos);
170
3.44k
  const int crop_or_scale = Extract(1, data, size, bit_pos);
171
3.44k
  const int width_ratio = 1 + Extract(7, data, size, bit_pos);
172
3.44k
  const int height_ratio = 1 + Extract(7, data, size, bit_pos);
173
3.44k
  if (alter_input) {
174
2.53k
    if (crop_or_scale) {
175
907
      const uint32_t left_ratio = 1 + Extract(7, data, size, bit_pos);
176
907
      const uint32_t top_ratio = 1 + Extract(7, data, size, bit_pos);
177
907
      const int cropped_width = max(1, pic->width / width_ratio);
178
907
      const int cropped_height = max(1, pic->height / height_ratio);
179
907
      const int cropped_left = (pic->width - cropped_width) / left_ratio;
180
907
      const int cropped_top = (pic->height - cropped_height) / top_ratio;
181
907
      return WebPPictureCrop(pic, cropped_left, cropped_top, cropped_width,
182
907
                             cropped_height);
183
1.63k
    } else {
184
1.63k
      const int scaled_width = 1 + (pic->width * width_ratio) / 8;
185
1.63k
      const int scaled_height = 1 + (pic->height * height_ratio) / 8;
186
1.63k
      return WebPPictureRescale(pic, scaled_width, scaled_height);
187
1.63k
    }
188
904
  }
189
904
  return 1;
190
904
}
fuzz_webp_enc_dec.cc:ExtractAndCropOrScale(WebPPicture*, unsigned char const*, unsigned long, unsigned int*)
Line
Count
Source
167
2.61k
                                 size_t size, uint32_t* const bit_pos) {
168
2.61k
  if (pic == NULL) return 0;
169
2.61k
  const int alter_input = Extract(1, data, size, bit_pos);
170
2.61k
  const int crop_or_scale = Extract(1, data, size, bit_pos);
171
2.61k
  const int width_ratio = 1 + Extract(7, data, size, bit_pos);
172
2.61k
  const int height_ratio = 1 + Extract(7, data, size, bit_pos);
173
2.61k
  if (alter_input) {
174
2.22k
    if (crop_or_scale) {
175
739
      const uint32_t left_ratio = 1 + Extract(7, data, size, bit_pos);
176
739
      const uint32_t top_ratio = 1 + Extract(7, data, size, bit_pos);
177
739
      const int cropped_width = max(1, pic->width / width_ratio);
178
739
      const int cropped_height = max(1, pic->height / height_ratio);
179
739
      const int cropped_left = (pic->width - cropped_width) / left_ratio;
180
739
      const int cropped_top = (pic->height - cropped_height) / top_ratio;
181
739
      return WebPPictureCrop(pic, cropped_left, cropped_top, cropped_width,
182
739
                             cropped_height);
183
1.48k
    } else {
184
1.48k
      const int scaled_width = 1 + (pic->width * width_ratio) / 8;
185
1.48k
      const int scaled_height = 1 + (pic->height * height_ratio) / 8;
186
1.48k
      return WebPPictureRescale(pic, scaled_width, scaled_height);
187
1.48k
    }
188
396
  }
189
396
  return 1;
190
396
}
Unexecuted instantiation: fuzz_simple_api.c:ExtractAndCropOrScale