Coverage Report

Created: 2025-08-24 07:17

/src/libxaac/fuzzer/xaac_enc_fuzzer.cpp
Line
Count
Source (jump to first uncovered line)
1
/******************************************************************************
2
 *                                                                            *
3
 * Copyright (C) 2023 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
 */
20
/*****************************************************************************/
21
/* File includes                                                             */
22
/*****************************************************************************/
23
#include <string.h>
24
#include <stdio.h>
25
#include <stdlib.h>
26
#include <stdint.h>
27
#include <fuzzer/FuzzedDataProvider.h>
28
29
extern "C" {
30
#include "ixheaac_type_def.h"
31
#include "impd_drc_common_enc.h"
32
#include "impd_drc_uni_drc.h"
33
#include "impd_drc_api.h"
34
#include "ixheaace_api.h"
35
#include "ixheaace_loudness_measurement.h"
36
}
37
38
static constexpr WORD32 k_sample_rates[] = {7350,  8000,  11025, 12000, 16000, 22050, 24000,
39
                                            32000, 44100, 48000, 64000, 88200, 96000};
40
static constexpr WORD16 k_frame_length[] = {480, 512, 768, 960, 1024};
41
42
94.9k
pVOID malloc_global(UWORD32 size, UWORD32 alignment) {
43
94.9k
  pVOID ptr = NULL;
44
94.9k
  if (posix_memalign((VOID **)&ptr, alignment, size)) {
45
0
    ptr = NULL;
46
0
  }
47
94.9k
  return ptr;
48
94.9k
}
49
50
83.2k
VOID free_global(pVOID ptr) { free(ptr); }
51
52
static VOID ixheaace_read_drc_config_params(
53
    ia_drc_enc_params_struct *pstr_enc_params, ia_drc_uni_drc_config_struct *pstr_uni_drc_config,
54
    ia_drc_loudness_info_set_struct *pstr_enc_loudness_info_set,
55
    ia_drc_uni_drc_gain_ext_struct *pstr_enc_gain_extension, FuzzedDataProvider *fuzzed_data,
56
4.23k
    WORD32 in_ch) {
57
4.23k
  WORD32 n, g, s, m, ch, p;
58
4.23k
  WORD32 gain_set_channels;
59
4.23k
#ifdef LOUDNESS_LEVELING_SUPPORT
60
4.23k
  UWORD32 loudness_leveling_extension_present = 0;
61
4.23k
  UWORD32 config_extension_count = 0;
62
4.23k
#endif
63
4.23k
  pstr_enc_params->gain_sequence_present = fuzzed_data->ConsumeBool();
64
4.23k
  pstr_enc_params->delay_mode = fuzzed_data->ConsumeBool();
65
4.23k
  pstr_uni_drc_config->sample_rate_present = fuzzed_data->ConsumeBool();
66
4.23k
  pstr_uni_drc_config->str_drc_coefficients_uni_drc->drc_frame_size_present =
67
4.23k
      fuzzed_data->ConsumeBool();
68
4.23k
  pstr_uni_drc_config->loudness_info_set_present = fuzzed_data->ConsumeBool();
69
70
4.23k
  pstr_uni_drc_config->drc_instructions_uni_drc_count =
71
4.23k
      fuzzed_data->ConsumeIntegralInRange<WORD8>(0, MAX_DRC_INSTRUCTIONS_COUNT);
72
27.4k
  for (n = 0; n < pstr_uni_drc_config->drc_instructions_uni_drc_count; n++) {
73
23.1k
    ia_drc_instructions_uni_drc *pstr_drc_instructions_uni_drc =
74
23.1k
        &pstr_uni_drc_config->str_drc_instructions_uni_drc[n];
75
23.1k
    pstr_drc_instructions_uni_drc->drc_set_id = fuzzed_data->ConsumeIntegral<WORD8>();
76
23.1k
    pstr_drc_instructions_uni_drc->downmix_id = fuzzed_data->ConsumeIntegral<WORD8>();
77
23.1k
    pstr_drc_instructions_uni_drc->additional_downmix_id_present = fuzzed_data->ConsumeBool();
78
23.1k
    pstr_drc_instructions_uni_drc->additional_downmix_id_count =
79
23.1k
        fuzzed_data->ConsumeIntegral<WORD8>();
80
23.1k
    pstr_drc_instructions_uni_drc->drc_location = fuzzed_data->ConsumeIntegral<WORD8>();
81
23.1k
    pstr_drc_instructions_uni_drc->depends_on_drc_set_present = fuzzed_data->ConsumeBool();
82
23.1k
    pstr_drc_instructions_uni_drc->depends_on_drc_set = fuzzed_data->ConsumeIntegral<WORD8>();
83
23.1k
    pstr_drc_instructions_uni_drc->no_independent_use = fuzzed_data->ConsumeBool();
84
23.1k
    pstr_drc_instructions_uni_drc->drc_set_effect = fuzzed_data->ConsumeIntegral<WORD16>();
85
23.1k
    pstr_drc_instructions_uni_drc->drc_set_target_loudness_present = fuzzed_data->ConsumeBool();
86
23.1k
    pstr_drc_instructions_uni_drc->drc_set_target_loudness_value_upper =
87
23.1k
        fuzzed_data->ConsumeIntegral<WORD8>();
88
23.1k
    pstr_drc_instructions_uni_drc->drc_set_target_loudness_value_lower_present =
89
23.1k
        fuzzed_data->ConsumeBool();
90
23.1k
    pstr_drc_instructions_uni_drc->drc_set_target_loudness_value_lower =
91
23.1k
        fuzzed_data->ConsumeIntegral<WORD8>();
92
93
23.1k
    gain_set_channels = fuzzed_data->ConsumeIntegralInRange<WORD8>(0, MAX_CHANNEL_COUNT);
94
87.6k
    for (ch = 0; ch < gain_set_channels; ch++) {
95
64.4k
      pstr_drc_instructions_uni_drc->gain_set_index[ch] = fuzzed_data->ConsumeIntegral<WORD8>();
96
64.4k
    }
97
144k
    for (; ch < MAX_CHANNEL_COUNT; ch++) {
98
121k
      if (gain_set_channels > 0) {
99
63.3k
        pstr_drc_instructions_uni_drc->gain_set_index[ch] =
100
63.3k
            pstr_drc_instructions_uni_drc->gain_set_index[gain_set_channels - 1];
101
63.3k
      } else {
102
57.7k
        pstr_drc_instructions_uni_drc->gain_set_index[ch] = 0;
103
57.7k
      }
104
121k
    }
105
106
23.1k
    pstr_drc_instructions_uni_drc->num_drc_channel_groups =
107
23.1k
        fuzzed_data->ConsumeIntegralInRange<WORD8>(0, MAX_CHANNEL_GROUP_COUNT);
108
86.8k
    for (g = 0; g < pstr_drc_instructions_uni_drc->num_drc_channel_groups; g++) {
109
63.6k
      pstr_drc_instructions_uni_drc->str_gain_modifiers[g].gain_scaling_present[0] =
110
63.6k
          fuzzed_data->ConsumeBool();
111
63.6k
      pstr_drc_instructions_uni_drc->str_gain_modifiers[g].attenuation_scaling[0] =
112
63.6k
          fuzzed_data->ConsumeFloatingPoint<FLOAT32>();
113
63.6k
      pstr_drc_instructions_uni_drc->str_gain_modifiers[g].amplification_scaling[0] =
114
63.6k
          fuzzed_data->ConsumeFloatingPoint<FLOAT32>();
115
63.6k
      pstr_drc_instructions_uni_drc->str_gain_modifiers[g].gain_offset_present[0] =
116
63.6k
          fuzzed_data->ConsumeBool();
117
63.6k
      pstr_drc_instructions_uni_drc->str_gain_modifiers[g].gain_offset[0] =
118
63.6k
          fuzzed_data->ConsumeFloatingPoint<FLOAT32>();
119
63.6k
    }
120
121
23.1k
    pstr_drc_instructions_uni_drc->limiter_peak_target_present = fuzzed_data->ConsumeBool();
122
23.1k
    pstr_drc_instructions_uni_drc->limiter_peak_target =
123
23.1k
        fuzzed_data->ConsumeFloatingPoint<FLOAT32>();
124
23.1k
    pstr_drc_instructions_uni_drc->drc_instructions_type = fuzzed_data->ConsumeIntegral<WORD8>();
125
23.1k
    pstr_drc_instructions_uni_drc->mae_group_id = fuzzed_data->ConsumeIntegral<WORD8>();
126
23.1k
    pstr_drc_instructions_uni_drc->mae_group_preset_id = fuzzed_data->ConsumeIntegral<WORD8>();
127
23.1k
#ifdef LOUDNESS_LEVELING_SUPPORT
128
23.1k
    if (pstr_drc_instructions_uni_drc->drc_set_effect & EFFECT_BIT_DUCK_SELF) {
129
9.90k
      pstr_drc_instructions_uni_drc->leveling_present = fuzzed_data->ConsumeBool();
130
9.90k
      pstr_drc_instructions_uni_drc->ducking_only_set_present = fuzzed_data->ConsumeBool();
131
9.90k
      loudness_leveling_extension_present = 1;
132
9.90k
    }
133
23.1k
#endif
134
23.1k
  }
135
136
4.23k
  pstr_uni_drc_config->drc_coefficients_uni_drc_count =
137
4.23k
      fuzzed_data->ConsumeIntegralInRange<WORD8>(0, MAX_DRC_COEFF_COUNT);
138
9.73k
  for (n = 0; n < pstr_uni_drc_config->drc_coefficients_uni_drc_count; n++) {
139
5.50k
    ia_drc_coefficients_uni_drc_struct *pstr_drc_coefficients_uni_drc =
140
5.50k
        &pstr_uni_drc_config->str_drc_coefficients_uni_drc[n];
141
5.50k
    pstr_drc_coefficients_uni_drc->drc_location = fuzzed_data->ConsumeIntegral<WORD8>();
142
5.50k
    pstr_drc_coefficients_uni_drc->gain_set_count =
143
5.50k
        fuzzed_data->ConsumeIntegralInRange<WORD8>(0, GAIN_SET_COUNT_MAX);
144
15.4k
    for (s = 0; s < pstr_drc_coefficients_uni_drc->gain_set_count; s++) {
145
9.91k
      pstr_drc_coefficients_uni_drc->str_gain_set_params[s].gain_coding_profile =
146
9.91k
          fuzzed_data->ConsumeIntegral<WORD8>();
147
9.91k
      pstr_drc_coefficients_uni_drc->str_gain_set_params[s].gain_interpolation_type =
148
9.91k
          fuzzed_data->ConsumeBool();
149
9.91k
      pstr_drc_coefficients_uni_drc->str_gain_set_params[s].full_frame =
150
9.91k
          fuzzed_data->ConsumeBool();
151
9.91k
      pstr_drc_coefficients_uni_drc->str_gain_set_params[s].time_alignment =
152
9.91k
          fuzzed_data->ConsumeBool();
153
9.91k
      pstr_drc_coefficients_uni_drc->str_gain_set_params[s].time_delta_min_present =
154
9.91k
          fuzzed_data->ConsumeBool();
155
9.91k
      pstr_drc_coefficients_uni_drc->str_gain_set_params[s].band_count =
156
9.91k
          fuzzed_data->ConsumeIntegralInRange<WORD8>(0, MAX_BAND_COUNT);
157
9.91k
      if (pstr_drc_coefficients_uni_drc->str_gain_set_params[s].band_count == 1) {
158
1.65k
        pstr_drc_coefficients_uni_drc->str_gain_set_params[s].gain_params[0].nb_points =
159
1.65k
            fuzzed_data->ConsumeIntegralInRange<WORD16>(0, MAX_GAIN_POINTS);
160
1.65k
        for (p = 0;
161
62.9k
             p < pstr_drc_coefficients_uni_drc->str_gain_set_params[s].gain_params[0].nb_points;
162
61.2k
             p++) {
163
61.2k
          pstr_drc_coefficients_uni_drc->str_gain_set_params[s].gain_params[0].gain_points[p].x =
164
61.2k
              fuzzed_data->ConsumeFloatingPoint<FLOAT32>();
165
61.2k
          pstr_drc_coefficients_uni_drc->str_gain_set_params[s].gain_params[0].gain_points[p].y =
166
61.2k
              fuzzed_data->ConsumeFloatingPoint<FLOAT32>();
167
61.2k
        }
168
1.65k
        pstr_drc_coefficients_uni_drc->str_gain_set_params[s].gain_params[0].width =
169
1.65k
            fuzzed_data->ConsumeFloatingPoint<FLOAT32>();
170
1.65k
        pstr_drc_coefficients_uni_drc->str_gain_set_params[s].gain_params[0].attack =
171
1.65k
            fuzzed_data->ConsumeFloatingPoint<FLOAT32>();
172
1.65k
        pstr_drc_coefficients_uni_drc->str_gain_set_params[s].gain_params[0].decay =
173
1.65k
            fuzzed_data->ConsumeFloatingPoint<FLOAT32>();
174
1.65k
        pstr_drc_coefficients_uni_drc->str_gain_set_params[s].gain_params[0].drc_characteristic =
175
1.65k
            fuzzed_data->ConsumeIntegral<WORD8>();
176
1.65k
        pstr_drc_coefficients_uni_drc->str_gain_set_params[s]
177
1.65k
            .gain_params[0]
178
1.65k
            .crossover_freq_index = fuzzed_data->ConsumeIntegral<WORD8>();
179
8.26k
      } else {
180
37.3k
        for (m = 0; m < pstr_drc_coefficients_uni_drc->str_gain_set_params[s].band_count; m++) {
181
29.0k
          pstr_drc_coefficients_uni_drc->str_gain_set_params[s].gain_params[m].nb_points =
182
29.0k
              fuzzed_data->ConsumeIntegralInRange<WORD16>(0, MAX_GAIN_POINTS);
183
29.0k
          for (p = 0;
184
1.02M
               p < pstr_drc_coefficients_uni_drc->str_gain_set_params[s].gain_params[m].nb_points;
185
990k
               p++) {
186
990k
            pstr_drc_coefficients_uni_drc->str_gain_set_params[s]
187
990k
                .gain_params[m]
188
990k
                .gain_points[p]
189
990k
                .x = fuzzed_data->ConsumeFloatingPoint<FLOAT32>();
190
990k
            pstr_drc_coefficients_uni_drc->str_gain_set_params[s]
191
990k
                .gain_params[m]
192
990k
                .gain_points[p]
193
990k
                .y = fuzzed_data->ConsumeFloatingPoint<FLOAT32>();
194
990k
          }
195
29.0k
          pstr_drc_coefficients_uni_drc->str_gain_set_params[s].gain_params[m].width =
196
29.0k
              fuzzed_data->ConsumeFloatingPoint<FLOAT32>();
197
29.0k
          pstr_drc_coefficients_uni_drc->str_gain_set_params[s].gain_params[m].attack =
198
29.0k
              fuzzed_data->ConsumeFloatingPoint<FLOAT32>();
199
29.0k
          pstr_drc_coefficients_uni_drc->str_gain_set_params[s].gain_params[m].decay =
200
29.0k
              fuzzed_data->ConsumeFloatingPoint<FLOAT32>();
201
29.0k
          pstr_drc_coefficients_uni_drc->str_gain_set_params[s].drc_band_type =
202
29.0k
              fuzzed_data->ConsumeBool();
203
29.0k
          pstr_drc_coefficients_uni_drc->str_gain_set_params[s]
204
29.0k
              .gain_params[m]
205
29.0k
              .start_sub_band_index = fuzzed_data->ConsumeIntegral<WORD16>();
206
29.0k
          pstr_drc_coefficients_uni_drc->str_gain_set_params[s]
207
29.0k
              .gain_params[m]
208
29.0k
              .drc_characteristic = fuzzed_data->ConsumeIntegral<WORD8>();
209
29.0k
          pstr_drc_coefficients_uni_drc->str_gain_set_params[s]
210
29.0k
              .gain_params[m]
211
29.0k
              .crossover_freq_index = fuzzed_data->ConsumeIntegral<WORD8>();
212
29.0k
        }
213
8.26k
      }
214
9.91k
    }
215
5.50k
  }
216
217
4.23k
  pstr_enc_loudness_info_set->loudness_info_count =
218
4.23k
      fuzzed_data->ConsumeIntegralInRange<WORD8>(0, MAX_LOUDNESS_INFO_COUNT);
219
24.1k
  for (n = 0; n < pstr_enc_loudness_info_set->loudness_info_count; n++) {
220
19.9k
    pstr_enc_loudness_info_set->str_loudness_info[n].drc_set_id =
221
19.9k
        fuzzed_data->ConsumeIntegral<WORD8>();
222
19.9k
    pstr_enc_loudness_info_set->str_loudness_info[n].downmix_id =
223
19.9k
        fuzzed_data->ConsumeIntegral<WORD8>();
224
19.9k
    pstr_enc_loudness_info_set->str_loudness_info[n].sample_peak_level_present =
225
19.9k
        fuzzed_data->ConsumeBool();
226
19.9k
    if (1 == pstr_enc_loudness_info_set->str_loudness_info[n].sample_peak_level_present) {
227
8.83k
      pstr_enc_loudness_info_set->str_loudness_info[n].sample_peak_level =
228
8.83k
          fuzzed_data->ConsumeFloatingPoint<FLOAT32>();
229
8.83k
    }
230
19.9k
    pstr_enc_loudness_info_set->str_loudness_info[n].true_peak_level_present =
231
19.9k
        fuzzed_data->ConsumeBool();
232
19.9k
    if (1 == pstr_enc_loudness_info_set->str_loudness_info[n].true_peak_level_present) {
233
9.15k
      pstr_enc_loudness_info_set->str_loudness_info[n].true_peak_level =
234
9.15k
          fuzzed_data->ConsumeFloatingPoint<FLOAT32>();
235
9.15k
      pstr_enc_loudness_info_set->str_loudness_info[n].true_peak_level_measurement_system =
236
9.15k
          fuzzed_data->ConsumeIntegral<WORD8>();
237
9.15k
      pstr_enc_loudness_info_set->str_loudness_info[n].true_peak_level_reliability =
238
9.15k
          fuzzed_data->ConsumeIntegral<WORD8>();
239
9.15k
    }
240
241
19.9k
    pstr_enc_loudness_info_set->str_loudness_info[n].measurement_count =
242
19.9k
        fuzzed_data->ConsumeIntegralInRange<WORD8>(0, MAX_MEASUREMENT_COUNT);
243
146k
    for (m = 0; m < pstr_enc_loudness_info_set->str_loudness_info[n].measurement_count; m++) {
244
126k
      pstr_enc_loudness_info_set->str_loudness_info[n].str_loudness_measure[m].method_definition =
245
126k
          fuzzed_data->ConsumeIntegral<WORD8>();
246
126k
      pstr_enc_loudness_info_set->str_loudness_info[n].str_loudness_measure[m].method_value =
247
126k
          fuzzed_data->ConsumeFloatingPoint<FLOAT32>();
248
126k
      pstr_enc_loudness_info_set->str_loudness_info[n]
249
126k
          .str_loudness_measure[m]
250
126k
          .measurement_system = fuzzed_data->ConsumeIntegral<WORD8>();
251
126k
      pstr_enc_loudness_info_set->str_loudness_info[n].str_loudness_measure[m].reliability =
252
126k
          fuzzed_data->ConsumeIntegral<WORD8>();
253
126k
    }
254
19.9k
  }
255
256
4.23k
  pstr_enc_loudness_info_set->loudness_info_album_count =
257
4.23k
      fuzzed_data->ConsumeIntegralInRange<WORD8>(0, MAX_LOUDNESS_INFO_COUNT);
258
26.2k
  for (n = 0; n < pstr_enc_loudness_info_set->loudness_info_album_count; n++) {
259
22.0k
    pstr_enc_loudness_info_set->str_loudness_info_album[n].drc_set_id =
260
22.0k
        fuzzed_data->ConsumeIntegral<WORD8>();
261
22.0k
    pstr_enc_loudness_info_set->str_loudness_info_album[n].downmix_id =
262
22.0k
        fuzzed_data->ConsumeIntegral<WORD8>();
263
22.0k
    pstr_enc_loudness_info_set->str_loudness_info_album[n].sample_peak_level_present =
264
22.0k
        fuzzed_data->ConsumeBool();
265
22.0k
    if (1 == pstr_enc_loudness_info_set->str_loudness_info_album[n].sample_peak_level_present) {
266
9.30k
      pstr_enc_loudness_info_set->str_loudness_info_album[n].sample_peak_level =
267
9.30k
          fuzzed_data->ConsumeFloatingPoint<FLOAT32>();
268
9.30k
    }
269
22.0k
    pstr_enc_loudness_info_set->str_loudness_info_album[n].true_peak_level_present =
270
22.0k
        fuzzed_data->ConsumeBool();
271
22.0k
    if (1 == pstr_enc_loudness_info_set->str_loudness_info_album[n].true_peak_level_present) {
272
10.8k
      pstr_enc_loudness_info_set->str_loudness_info_album[n].true_peak_level =
273
10.8k
          fuzzed_data->ConsumeFloatingPoint<FLOAT32>();
274
10.8k
      pstr_enc_loudness_info_set->str_loudness_info_album[n].true_peak_level_measurement_system =
275
10.8k
          fuzzed_data->ConsumeIntegral<WORD8>();
276
10.8k
      pstr_enc_loudness_info_set->str_loudness_info_album[n].true_peak_level_reliability =
277
10.8k
          fuzzed_data->ConsumeIntegral<WORD8>();
278
10.8k
    }
279
280
22.0k
    pstr_enc_loudness_info_set->str_loudness_info_album[n].measurement_count =
281
22.0k
        fuzzed_data->ConsumeIntegralInRange<WORD8>(0, MAX_MEASUREMENT_COUNT);
282
160k
    for (m = 0; m < pstr_enc_loudness_info_set->str_loudness_info_album[n].measurement_count;
283
137k
         m++) {
284
137k
      pstr_enc_loudness_info_set->str_loudness_info_album[n]
285
137k
          .str_loudness_measure[m]
286
137k
          .method_definition = fuzzed_data->ConsumeIntegral<WORD8>();
287
137k
      pstr_enc_loudness_info_set->str_loudness_info_album[n]
288
137k
          .str_loudness_measure[m]
289
137k
          .method_value = fuzzed_data->ConsumeFloatingPoint<FLOAT32>();
290
137k
      pstr_enc_loudness_info_set->str_loudness_info_album[n]
291
137k
          .str_loudness_measure[m]
292
137k
          .measurement_system = fuzzed_data->ConsumeIntegral<WORD8>();
293
137k
      pstr_enc_loudness_info_set->str_loudness_info_album[n].str_loudness_measure[m].reliability =
294
137k
          fuzzed_data->ConsumeIntegral<WORD8>();
295
137k
    }
296
22.0k
  }
297
298
4.23k
  pstr_uni_drc_config->str_channel_layout.layout_signaling_present = fuzzed_data->ConsumeBool();
299
4.23k
  pstr_uni_drc_config->str_channel_layout.defined_layout = fuzzed_data->ConsumeIntegral<WORD8>();
300
4.23k
  pstr_uni_drc_config->str_channel_layout.speaker_position[0] =
301
4.23k
      fuzzed_data->ConsumeIntegral<WORD8>();
302
303
4.23k
  pstr_uni_drc_config->downmix_instructions_count =
304
4.23k
      fuzzed_data->ConsumeIntegralInRange<WORD8>(0, MAX_DOWNMIX_INSTRUCTION_COUNT);
305
23.4k
  for (n = 0; n < pstr_uni_drc_config->downmix_instructions_count; n++) {
306
19.2k
    pstr_uni_drc_config->str_downmix_instructions[n].target_layout =
307
19.2k
        fuzzed_data->ConsumeIntegral<WORD8>();
308
19.2k
    pstr_uni_drc_config->str_downmix_instructions[n].downmix_coefficients_present =
309
19.2k
        fuzzed_data->ConsumeBool();
310
19.2k
  }
311
312
4.23k
  pstr_uni_drc_config->drc_description_basic_present = fuzzed_data->ConsumeBool();
313
4.23k
  pstr_uni_drc_config->uni_drc_config_ext_present = fuzzed_data->ConsumeBool();
314
4.23k
  pstr_enc_loudness_info_set->loudness_info_set_ext_present = fuzzed_data->ConsumeBool();
315
4.23k
  pstr_enc_gain_extension->uni_drc_gain_ext_present = fuzzed_data->ConsumeBool();
316
317
4.23k
  if (pstr_uni_drc_config->uni_drc_config_ext_present == 1) {
318
2.24k
#ifdef LOUDNESS_LEVELING_SUPPORT
319
2.24k
    pstr_uni_drc_config->str_uni_drc_config_ext.uni_drc_config_ext_type[config_extension_count] =
320
2.24k
        UNIDRC_CONF_EXT_V1;
321
2.24k
    config_extension_count++;
322
#else
323
    pstr_uni_drc_config->str_uni_drc_config_ext.uni_drc_config_ext_type[0] = UNIDRC_CONF_EXT_V1;
324
#endif
325
2.24k
    pstr_uni_drc_config->str_uni_drc_config_ext.downmix_instructions_v1_present =
326
2.24k
        fuzzed_data->ConsumeBool();
327
2.24k
    if (pstr_uni_drc_config->str_uni_drc_config_ext.downmix_instructions_v1_present == 1) {
328
      /***********  str_downmix_instructions_v1  *************/
329
330
940
      pstr_uni_drc_config->str_uni_drc_config_ext.downmix_instructions_v1_count =
331
940
          fuzzed_data->ConsumeIntegralInRange<WORD8>(0, DOWNMIX_INSTRUCTIONS_COUNT_MAX);
332
4.80k
      for (n = 0; n < pstr_uni_drc_config->str_uni_drc_config_ext.downmix_instructions_v1_count;
333
3.86k
           n++) {
334
3.86k
        ia_drc_downmix_instructions_struct *pstr_downmix_instructions_v1 =
335
3.86k
            &pstr_uni_drc_config->str_uni_drc_config_ext.str_downmix_instructions_v1[n];
336
3.86k
        pstr_downmix_instructions_v1->downmix_id = fuzzed_data->ConsumeIntegral<WORD8>();
337
3.86k
        ;
338
3.86k
        pstr_downmix_instructions_v1->target_ch_count = fuzzed_data->ConsumeIntegral<WORD8>();
339
3.86k
        pstr_downmix_instructions_v1->target_layout = fuzzed_data->ConsumeIntegral<WORD8>();
340
3.86k
        pstr_downmix_instructions_v1->downmix_coefficients_present = fuzzed_data->ConsumeBool();
341
3.86k
        if (pstr_downmix_instructions_v1->downmix_coefficients_present) {
342
2.86k
          FLOAT32 dwn_mix_coeff = 0.0f;
343
69.7k
          for (s = 0; s < pstr_downmix_instructions_v1->target_layout; s++) {
344
66.9k
            dwn_mix_coeff = fuzzed_data->ConsumeFloatingPoint<FLOAT32>();
345
66.9k
            for (ch = 0; ch < in_ch; ch++) {
346
0
              pstr_downmix_instructions_v1->downmix_coeff[in_ch * s + ch] = dwn_mix_coeff;
347
0
            }
348
66.9k
          }
349
2.86k
        }
350
3.86k
      }
351
940
    }
352
353
2.24k
    pstr_uni_drc_config->str_uni_drc_config_ext.drc_coeffs_and_instructions_uni_drc_v1_present =
354
2.24k
        fuzzed_data->ConsumeBool();
355
2.24k
    if (pstr_uni_drc_config->str_uni_drc_config_ext
356
2.24k
            .drc_coeffs_and_instructions_uni_drc_v1_present == 1) {
357
      /***********  str_drc_coefficients_uni_drc_v1  *************/
358
359
2.05k
      pstr_uni_drc_config->str_uni_drc_config_ext.drc_coefficients_uni_drc_v1_count =
360
2.05k
          fuzzed_data->ConsumeIntegralInRange<WORD8>(0, DRC_COEFFICIENTS_UNIDRC_V1_COUNT_MAX);
361
2.05k
      for (n = 0;
362
4.36k
           n < pstr_uni_drc_config->str_uni_drc_config_ext.drc_coefficients_uni_drc_v1_count;
363
2.31k
           n++) {
364
2.31k
        ia_drc_coefficients_uni_drc_struct *pstr_drc_coefficients_uni_drc_v1 =
365
2.31k
            &pstr_uni_drc_config->str_uni_drc_config_ext.str_drc_coefficients_uni_drc_v1[n];
366
2.31k
        pstr_drc_coefficients_uni_drc_v1->drc_location = fuzzed_data->ConsumeIntegral<WORD8>();
367
2.31k
        pstr_drc_coefficients_uni_drc_v1->gain_set_count =
368
2.31k
            fuzzed_data->ConsumeIntegralInRange<WORD8>(0, GAIN_SET_COUNT_MAX);
369
8.25k
        for (s = 0; s < pstr_drc_coefficients_uni_drc_v1->gain_set_count; s++) {
370
5.94k
          pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s].gain_coding_profile =
371
5.94k
              fuzzed_data->ConsumeIntegral<WORD8>();
372
5.94k
          pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s].gain_interpolation_type =
373
5.94k
              fuzzed_data->ConsumeBool();
374
5.94k
          pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s].full_frame =
375
5.94k
              fuzzed_data->ConsumeBool();
376
5.94k
          pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s].time_alignment =
377
5.94k
              fuzzed_data->ConsumeBool();
378
5.94k
          pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s].time_delta_min_present =
379
5.94k
              fuzzed_data->ConsumeBool();
380
5.94k
          pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s].band_count =
381
5.94k
              fuzzed_data->ConsumeIntegralInRange<WORD8>(0, MAX_BAND_COUNT);
382
5.94k
          if (pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s].band_count == 1) {
383
1.62k
            pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s].gain_params[0].nb_points =
384
1.62k
                fuzzed_data->ConsumeIntegralInRange<WORD16>(0, MAX_GAIN_POINTS);
385
53.6k
            for (p = 0; p < pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s]
386
53.6k
                                .gain_params[0]
387
53.6k
                                .nb_points;
388
52.0k
                 p++) {
389
52.0k
              pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s]
390
52.0k
                  .gain_params[0]
391
52.0k
                  .gain_points[p]
392
52.0k
                  .x = fuzzed_data->ConsumeFloatingPoint<FLOAT32>();
393
52.0k
              pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s]
394
52.0k
                  .gain_params[0]
395
52.0k
                  .gain_points[p]
396
52.0k
                  .y = fuzzed_data->ConsumeFloatingPoint<FLOAT32>();
397
52.0k
            }
398
1.62k
            pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s].gain_params[0].width =
399
1.62k
                fuzzed_data->ConsumeFloatingPoint<FLOAT32>();
400
1.62k
            pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s].gain_params[0].attack =
401
1.62k
                fuzzed_data->ConsumeFloatingPoint<FLOAT32>();
402
1.62k
            pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s].gain_params[0].decay =
403
1.62k
                fuzzed_data->ConsumeFloatingPoint<FLOAT32>();
404
1.62k
            pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s]
405
1.62k
                .gain_params[0]
406
1.62k
                .drc_characteristic = fuzzed_data->ConsumeIntegral<WORD8>();
407
1.62k
            ;
408
1.62k
            pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s]
409
1.62k
                .gain_params[0]
410
1.62k
                .crossover_freq_index = fuzzed_data->ConsumeIntegral<WORD8>();
411
4.32k
          } else {
412
20.0k
            for (m = 0; m < pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s].band_count;
413
15.7k
                 m++) {
414
15.7k
              pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s].gain_params[m].nb_points =
415
15.7k
                  fuzzed_data->ConsumeIntegralInRange<WORD16>(0, MAX_GAIN_POINTS);
416
418k
              for (p = 0; p < pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s]
417
418k
                                  .gain_params[m]
418
418k
                                  .nb_points;
419
403k
                   p++) {
420
403k
                pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s]
421
403k
                    .gain_params[m]
422
403k
                    .gain_points[p]
423
403k
                    .x = fuzzed_data->ConsumeFloatingPoint<FLOAT32>();
424
403k
                pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s]
425
403k
                    .gain_params[m]
426
403k
                    .gain_points[p]
427
403k
                    .y = fuzzed_data->ConsumeFloatingPoint<FLOAT32>();
428
403k
              }
429
15.7k
              pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s].gain_params[m].width =
430
15.7k
                  fuzzed_data->ConsumeFloatingPoint<FLOAT32>();
431
15.7k
              pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s].gain_params[m].attack =
432
15.7k
                  fuzzed_data->ConsumeFloatingPoint<FLOAT32>();
433
15.7k
              pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s].gain_params[m].decay =
434
15.7k
                  fuzzed_data->ConsumeFloatingPoint<FLOAT32>();
435
15.7k
              pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s].drc_band_type = 0;
436
15.7k
              pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s]
437
15.7k
                  .gain_params[m]
438
15.7k
                  .start_sub_band_index = fuzzed_data->ConsumeIntegral<WORD16>();
439
15.7k
              pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s]
440
15.7k
                  .gain_params[m]
441
15.7k
                  .drc_characteristic = fuzzed_data->ConsumeIntegral<WORD8>();
442
15.7k
              ;
443
15.7k
              pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s]
444
15.7k
                  .gain_params[m]
445
15.7k
                  .crossover_freq_index = fuzzed_data->ConsumeIntegral<WORD8>();
446
15.7k
            }
447
4.32k
          }
448
5.94k
        }
449
2.31k
      }
450
451
      /***********  str_drc_instructions_uni_drc_v1  *************/
452
2.05k
      pstr_uni_drc_config->str_uni_drc_config_ext.drc_instructions_uni_drc_v1_count =
453
2.05k
          fuzzed_data->ConsumeIntegralInRange<WORD8>(0, DRC_INSTRUCTIONS_UNIDRC_V1_COUNT_MAX);
454
2.05k
      for (n = 0;
455
5.93k
           n < pstr_uni_drc_config->str_uni_drc_config_ext.drc_instructions_uni_drc_v1_count;
456
3.88k
           n++) {
457
3.88k
        ia_drc_instructions_uni_drc *pstr_drc_instructions_uni_drc =
458
3.88k
            &pstr_uni_drc_config->str_uni_drc_config_ext.str_drc_instructions_uni_drc_v1[n];
459
3.88k
        pstr_drc_instructions_uni_drc->drc_set_id = fuzzed_data->ConsumeIntegral<WORD8>();
460
3.88k
        pstr_drc_instructions_uni_drc->downmix_id = fuzzed_data->ConsumeIntegral<WORD8>();
461
3.88k
        pstr_drc_instructions_uni_drc->additional_downmix_id_present = fuzzed_data->ConsumeBool();
462
3.88k
        pstr_drc_instructions_uni_drc->additional_downmix_id_count =
463
3.88k
            fuzzed_data->ConsumeIntegral<WORD8>();
464
3.88k
        pstr_drc_instructions_uni_drc->drc_location = fuzzed_data->ConsumeIntegral<WORD8>();
465
3.88k
        pstr_drc_instructions_uni_drc->depends_on_drc_set_present = fuzzed_data->ConsumeBool();
466
3.88k
        pstr_drc_instructions_uni_drc->depends_on_drc_set = fuzzed_data->ConsumeIntegral<WORD8>();
467
3.88k
        pstr_drc_instructions_uni_drc->no_independent_use = fuzzed_data->ConsumeBool();
468
3.88k
        pstr_drc_instructions_uni_drc->drc_set_effect = fuzzed_data->ConsumeIntegral<WORD16>();
469
3.88k
        pstr_drc_instructions_uni_drc->drc_set_target_loudness_present =
470
3.88k
            fuzzed_data->ConsumeBool();
471
3.88k
        pstr_drc_instructions_uni_drc->drc_set_target_loudness_value_upper =
472
3.88k
            fuzzed_data->ConsumeIntegral<WORD8>();
473
3.88k
        pstr_drc_instructions_uni_drc->drc_set_target_loudness_value_lower_present =
474
3.88k
            fuzzed_data->ConsumeBool();
475
3.88k
        pstr_drc_instructions_uni_drc->drc_set_target_loudness_value_lower =
476
3.88k
            fuzzed_data->ConsumeIntegral<WORD8>();
477
478
3.88k
        gain_set_channels = fuzzed_data->ConsumeIntegralInRange<WORD8>(0, MAX_CHANNEL_COUNT);
479
16.5k
        for (ch = 0; ch < gain_set_channels; ch++) {
480
12.6k
          pstr_drc_instructions_uni_drc->gain_set_index[ch] =
481
12.6k
              fuzzed_data->ConsumeIntegral<WORD8>();
482
12.6k
        }
483
22.2k
        for (; ch < MAX_CHANNEL_COUNT; ch++) {
484
18.4k
          if (gain_set_channels > 0) {
485
10.1k
            pstr_drc_instructions_uni_drc->gain_set_index[ch] =
486
10.1k
                pstr_drc_instructions_uni_drc->gain_set_index[gain_set_channels - 1];
487
10.1k
          } else {
488
8.27k
            pstr_drc_instructions_uni_drc->gain_set_index[ch] = 0;
489
8.27k
          }
490
18.4k
        }
491
492
3.88k
        pstr_drc_instructions_uni_drc->num_drc_channel_groups =
493
3.88k
            fuzzed_data->ConsumeIntegralInRange<WORD8>(0, MAX_CHANNEL_GROUP_COUNT);
494
16.1k
        for (g = 0; g < pstr_drc_instructions_uni_drc->num_drc_channel_groups; g++) {
495
12.2k
          pstr_drc_instructions_uni_drc->str_gain_modifiers[g].gain_scaling_present[0] =
496
12.2k
              fuzzed_data->ConsumeBool();
497
12.2k
          pstr_drc_instructions_uni_drc->str_gain_modifiers[g].attenuation_scaling[0] =
498
12.2k
              fuzzed_data->ConsumeFloatingPoint<FLOAT32>();
499
12.2k
          pstr_drc_instructions_uni_drc->str_gain_modifiers[g].amplification_scaling[0] =
500
12.2k
              fuzzed_data->ConsumeFloatingPoint<FLOAT32>();
501
12.2k
          pstr_drc_instructions_uni_drc->str_gain_modifiers[g].gain_offset_present[0] =
502
12.2k
              fuzzed_data->ConsumeBool();
503
12.2k
          pstr_drc_instructions_uni_drc->str_gain_modifiers[g].gain_offset[0] =
504
12.2k
              fuzzed_data->ConsumeFloatingPoint<FLOAT32>();
505
12.2k
        }
506
507
3.88k
        pstr_drc_instructions_uni_drc->limiter_peak_target_present = fuzzed_data->ConsumeBool();
508
3.88k
        pstr_drc_instructions_uni_drc->limiter_peak_target =
509
3.88k
            fuzzed_data->ConsumeFloatingPoint<FLOAT32>();
510
3.88k
        pstr_drc_instructions_uni_drc->drc_instructions_type =
511
3.88k
            fuzzed_data->ConsumeIntegral<WORD8>();
512
3.88k
        pstr_drc_instructions_uni_drc->mae_group_id = fuzzed_data->ConsumeIntegral<WORD8>();
513
3.88k
        pstr_drc_instructions_uni_drc->mae_group_preset_id =
514
3.88k
            fuzzed_data->ConsumeIntegral<WORD8>();
515
3.88k
#ifdef LOUDNESS_LEVELING_SUPPORT
516
517
3.88k
        if (pstr_drc_instructions_uni_drc->drc_set_effect & EFFECT_BIT_DUCK_SELF) {
518
1.51k
          pstr_drc_instructions_uni_drc->leveling_present = fuzzed_data->ConsumeBool();
519
1.51k
          pstr_drc_instructions_uni_drc->ducking_only_set_present = fuzzed_data->ConsumeBool();
520
1.51k
          loudness_leveling_extension_present = 1;
521
1.51k
        }
522
3.88k
#endif
523
3.88k
      }
524
2.05k
    }
525
2.24k
#ifdef LOUDNESS_LEVELING_SUPPORT
526
2.24k
    if (loudness_leveling_extension_present) {
527
716
      pstr_uni_drc_config->str_uni_drc_config_ext
528
716
          .uni_drc_config_ext_type[config_extension_count] = UNIDRCCONFEXT_LEVELING;
529
716
      config_extension_count++;
530
716
    }
531
2.24k
#endif
532
2.24k
  }
533
534
4.23k
  if (pstr_enc_loudness_info_set->loudness_info_set_ext_present == 1) {
535
2.13k
    ia_drc_loudness_info_set_ext_eq_struct *pstr_loudness_info_set_ext_eq =
536
2.13k
        &pstr_enc_loudness_info_set->str_loudness_info_set_extension.str_loudness_info_set_ext_eq;
537
538
2.13k
    pstr_enc_loudness_info_set->str_loudness_info_set_extension.loudness_info_set_ext_type[0] =
539
2.13k
        UNIDRC_LOUD_EXT_EQ;
540
541
    /*********************   loudness_info_v1_album   *********************/
542
2.13k
    pstr_loudness_info_set_ext_eq->loudness_info_v1_album_count =
543
2.13k
        fuzzed_data->ConsumeIntegralInRange<WORD8>(0, MAX_LOUDNESS_INFO_COUNT);
544
19.0k
    for (n = 0; n < pstr_loudness_info_set_ext_eq->loudness_info_v1_album_count; n++) {
545
16.8k
      pstr_loudness_info_set_ext_eq->str_loudness_info_v1_album[n].drc_set_id =
546
16.8k
          fuzzed_data->ConsumeIntegral<WORD8>();
547
16.8k
      pstr_loudness_info_set_ext_eq->str_loudness_info_v1_album[n].downmix_id =
548
16.8k
          fuzzed_data->ConsumeIntegral<WORD8>();
549
16.8k
      pstr_loudness_info_set_ext_eq->str_loudness_info_v1_album[n].sample_peak_level_present =
550
16.8k
          fuzzed_data->ConsumeBool();
551
16.8k
      if (pstr_loudness_info_set_ext_eq->str_loudness_info_v1_album[n]
552
16.8k
              .sample_peak_level_present == 1) {
553
9.39k
        pstr_loudness_info_set_ext_eq->str_loudness_info_v1_album[n].sample_peak_level =
554
9.39k
            fuzzed_data->ConsumeFloatingPoint<FLOAT32>();
555
9.39k
      }
556
16.8k
      pstr_loudness_info_set_ext_eq->str_loudness_info_v1_album[n].true_peak_level_present =
557
16.8k
          fuzzed_data->ConsumeBool();
558
16.8k
      if (pstr_loudness_info_set_ext_eq->str_loudness_info_v1_album[n].true_peak_level_present ==
559
16.8k
          1) {
560
10.4k
        pstr_loudness_info_set_ext_eq->str_loudness_info_v1_album[n].true_peak_level =
561
10.4k
            fuzzed_data->ConsumeFloatingPoint<FLOAT32>();
562
10.4k
        pstr_loudness_info_set_ext_eq->str_loudness_info_v1_album[n]
563
10.4k
            .true_peak_level_measurement_system = fuzzed_data->ConsumeIntegral<WORD8>();
564
10.4k
        pstr_loudness_info_set_ext_eq->str_loudness_info_v1_album[n].true_peak_level_reliability =
565
10.4k
            fuzzed_data->ConsumeIntegral<WORD8>();
566
10.4k
      }
567
16.8k
      pstr_loudness_info_set_ext_eq->str_loudness_info_v1_album[n].measurement_count =
568
16.8k
          fuzzed_data->ConsumeIntegralInRange<WORD8>(0, MAX_MEASUREMENT_COUNT);
569
16.8k
      for (m = 0;
570
126k
           m < pstr_loudness_info_set_ext_eq->str_loudness_info_v1_album[n].measurement_count;
571
109k
           m++) {
572
109k
        pstr_loudness_info_set_ext_eq->str_loudness_info_v1_album[n]
573
109k
            .str_loudness_measure[m]
574
109k
            .method_definition = fuzzed_data->ConsumeIntegral<WORD8>();
575
109k
        pstr_loudness_info_set_ext_eq->str_loudness_info_v1_album[n]
576
109k
            .str_loudness_measure[m]
577
109k
            .method_value = fuzzed_data->ConsumeFloatingPoint<FLOAT32>();
578
109k
        pstr_loudness_info_set_ext_eq->str_loudness_info_v1_album[n]
579
109k
            .str_loudness_measure[m]
580
109k
            .measurement_system = fuzzed_data->ConsumeIntegral<WORD8>();
581
109k
        pstr_loudness_info_set_ext_eq->str_loudness_info_v1_album[n]
582
109k
            .str_loudness_measure[m]
583
109k
            .reliability = fuzzed_data->ConsumeIntegral<WORD8>();
584
109k
      }
585
16.8k
    }
586
587
    /*********************   loudness_info_v1   *********************/
588
2.13k
    pstr_loudness_info_set_ext_eq->loudness_info_v1_count =
589
2.13k
        fuzzed_data->ConsumeIntegralInRange<WORD8>(0, MAX_LOUDNESS_INFO_COUNT);
590
18.7k
    for (n = 0; n < pstr_loudness_info_set_ext_eq->loudness_info_v1_count; n++) {
591
16.6k
      pstr_loudness_info_set_ext_eq->str_loudness_info_v1[n].drc_set_id =
592
16.6k
          fuzzed_data->ConsumeIntegral<WORD8>();
593
16.6k
      pstr_loudness_info_set_ext_eq->str_loudness_info_v1[n].downmix_id =
594
16.6k
          fuzzed_data->ConsumeIntegral<WORD8>();
595
16.6k
      pstr_loudness_info_set_ext_eq->str_loudness_info_v1[n].sample_peak_level_present =
596
16.6k
          fuzzed_data->ConsumeBool();
597
16.6k
      if (pstr_loudness_info_set_ext_eq->str_loudness_info_v1[n].sample_peak_level_present == 1) {
598
9.21k
        pstr_loudness_info_set_ext_eq->str_loudness_info_v1[n].sample_peak_level =
599
9.21k
            fuzzed_data->ConsumeFloatingPoint<FLOAT32>();
600
9.21k
      }
601
16.6k
      pstr_loudness_info_set_ext_eq->str_loudness_info_v1[n].true_peak_level_present =
602
16.6k
          fuzzed_data->ConsumeBool();
603
16.6k
      if (pstr_loudness_info_set_ext_eq->str_loudness_info_v1[n].true_peak_level_present == 1) {
604
10.7k
        pstr_loudness_info_set_ext_eq->str_loudness_info_v1[n].true_peak_level =
605
10.7k
            fuzzed_data->ConsumeFloatingPoint<FLOAT32>();
606
10.7k
        pstr_loudness_info_set_ext_eq->str_loudness_info_v1[n]
607
10.7k
            .true_peak_level_measurement_system = fuzzed_data->ConsumeIntegral<WORD8>();
608
10.7k
        pstr_loudness_info_set_ext_eq->str_loudness_info_v1[n].true_peak_level_reliability =
609
10.7k
            fuzzed_data->ConsumeIntegral<WORD8>();
610
10.7k
      }
611
16.6k
      pstr_loudness_info_set_ext_eq->str_loudness_info_v1[n].measurement_count =
612
16.6k
          fuzzed_data->ConsumeIntegralInRange<WORD8>(0, MAX_MEASUREMENT_COUNT);
613
131k
      for (m = 0; m < pstr_loudness_info_set_ext_eq->str_loudness_info_v1[n].measurement_count;
614
114k
           m++) {
615
114k
        pstr_loudness_info_set_ext_eq->str_loudness_info_v1[n]
616
114k
            .str_loudness_measure[m]
617
114k
            .method_definition = fuzzed_data->ConsumeIntegral<WORD8>();
618
114k
        pstr_loudness_info_set_ext_eq->str_loudness_info_v1[n]
619
114k
            .str_loudness_measure[m]
620
114k
            .method_value = fuzzed_data->ConsumeFloatingPoint<FLOAT32>();
621
114k
        pstr_loudness_info_set_ext_eq->str_loudness_info_v1[n]
622
114k
            .str_loudness_measure[m]
623
114k
            .measurement_system = fuzzed_data->ConsumeIntegral<WORD8>();
624
114k
        pstr_loudness_info_set_ext_eq->str_loudness_info_v1[n]
625
114k
            .str_loudness_measure[m]
626
114k
            .reliability = fuzzed_data->ConsumeIntegral<WORD8>();
627
114k
      }
628
16.6k
    }
629
2.13k
  }
630
4.23k
}
631
632
static VOID ixheaace_fuzzer_flag(ixheaace_input_config *pstr_in_cfg,
633
                                 ia_drc_input_config *pstr_drc_cfg,
634
11.6k
                                 FuzzedDataProvider *fuzzed_data, WORD32 in_ch) {
635
  // Set Default value for AAC config structure
636
637
11.6k
  pstr_in_cfg->i_bitrate = fuzzed_data->ConsumeIntegral<WORD32>();
638
11.6k
  pstr_in_cfg->i_use_mps = fuzzed_data->ConsumeBool();
639
11.6k
  pstr_in_cfg->i_use_adts = fuzzed_data->ConsumeBool();
640
11.6k
  pstr_in_cfg->i_use_es = fuzzed_data->ConsumeBool();
641
11.6k
  pstr_in_cfg->aac_config.use_tns = fuzzed_data->ConsumeBool();
642
11.6k
  pstr_in_cfg->aac_config.noise_filling = fuzzed_data->ConsumeBool();
643
11.6k
  pstr_in_cfg->ui_pcm_wd_sz = fuzzed_data->ConsumeIntegral<WORD8>();
644
11.6k
  pstr_in_cfg->i_channels = fuzzed_data->ConsumeIntegral<WORD8>();
645
11.6k
  if (fuzzed_data->ConsumeBool()) {
646
9.52k
    pstr_in_cfg->i_samp_freq = fuzzed_data->PickValueInArray(k_sample_rates);
647
9.52k
  } else {
648
2.13k
    pstr_in_cfg->i_samp_freq = fuzzed_data->ConsumeIntegral<UWORD32>();
649
2.13k
  }
650
11.6k
  if (fuzzed_data->ConsumeBool()) {
651
9.00k
    pstr_in_cfg->frame_length = fuzzed_data->PickValueInArray(k_frame_length);
652
9.00k
  } else {
653
2.66k
    pstr_in_cfg->frame_length = fuzzed_data->ConsumeIntegral<WORD16>();
654
2.66k
  }
655
11.6k
  pstr_in_cfg->aot = fuzzed_data->ConsumeIntegral<WORD8>();
656
11.6k
  pstr_in_cfg->esbr_flag = fuzzed_data->ConsumeBool();
657
11.6k
  pstr_in_cfg->aac_config.full_bandwidth = fuzzed_data->ConsumeBool();
658
11.6k
  pstr_in_cfg->aac_config.bitreservoir_size = fuzzed_data->ConsumeIntegral<WORD16>();
659
11.6k
  pstr_in_cfg->i_mps_tree_config = fuzzed_data->ConsumeIntegral<WORD8>();
660
11.6k
  pstr_in_cfg->i_channels_mask = fuzzed_data->ConsumeIntegral<WORD8>();
661
11.6k
  pstr_in_cfg->cplx_pred = fuzzed_data->ConsumeBool();
662
11.6k
  pstr_in_cfg->usac_en = fuzzed_data->ConsumeBool();
663
11.6k
  pstr_in_cfg->ccfl_idx = fuzzed_data->ConsumeIntegral<WORD8>();
664
11.6k
  pstr_in_cfg->pvc_active = fuzzed_data->ConsumeBool();
665
11.6k
  pstr_in_cfg->harmonic_sbr = fuzzed_data->ConsumeBool();
666
11.6k
  pstr_in_cfg->hq_esbr = fuzzed_data->ConsumeBool();
667
11.6k
  pstr_in_cfg->use_drc_element = fuzzed_data->ConsumeBool();
668
11.6k
  pstr_in_cfg->inter_tes_active = fuzzed_data->ConsumeBool();
669
11.6k
  pstr_in_cfg->codec_mode = fuzzed_data->ConsumeIntegral<WORD8>();
670
11.6k
  pstr_in_cfg->random_access_interval = fuzzed_data->ConsumeIntegral<WORD32>();
671
11.6k
  pstr_in_cfg->method_def = fuzzed_data->ConsumeIntegral<WORD32>();
672
11.6k
  pstr_in_cfg->measurement_system = fuzzed_data->ConsumeIntegral<WORD32>();
673
11.6k
  pstr_in_cfg->measured_loudness = fuzzed_data->ConsumeIntegral<WORD32>();
674
11.6k
  pstr_in_cfg->stream_id = fuzzed_data->ConsumeIntegral<UWORD16>();
675
11.6k
  pstr_in_cfg->use_delay_adjustment = fuzzed_data->ConsumeIntegral<WORD32>();
676
  /* DRC */
677
11.6k
  if (pstr_in_cfg->use_drc_element == 1) {
678
4.23k
    ixheaace_read_drc_config_params(&pstr_drc_cfg->str_enc_params,
679
4.23k
                                    &pstr_drc_cfg->str_uni_drc_config,
680
4.23k
                                    &pstr_drc_cfg->str_enc_loudness_info_set,
681
4.23k
                                    &pstr_drc_cfg->str_enc_gain_extension, fuzzed_data, in_ch);
682
4.23k
  }
683
11.6k
}
684
685
IA_ERRORCODE ia_enhaacplus_enc_pcm_data_read(std::vector<WORD8> input_vec, UWORD32 num_samples,
686
62.5k
                                             WORD32 num_channels, WORD16 **data) {
687
62.5k
  UWORD32 count = 0;
688
62.5k
  UWORD8 channel_no;
689
62.5k
  UWORD32 sample_no = 0;
690
62.5k
  UWORD32 i = 0;
691
224M
  while (count < num_samples) {
692
224M
    sample_no = (count / num_channels);
693
224M
    channel_no = (UWORD8)(count % num_channels);
694
224M
    data[channel_no][sample_no] = *input_vec.data();
695
224M
    i++;
696
224M
    count++;
697
224M
  }
698
62.5k
  return 0;
699
62.5k
}
700
701
static IA_ERRORCODE ixheaace_calculate_loudness_measure(ixheaace_input_config *pstr_in_cfg,
702
                                                        ixheaace_output_config *pstr_out_cfg,
703
7.35k
                                                        FuzzedDataProvider *fuzzed_data) {
704
7.35k
  WORD32 input_size;
705
7.35k
  WORD32 count = 0;
706
7.35k
  IA_ERRORCODE err_code = 0;
707
7.35k
  VOID *loudness_handle =
708
7.35k
      malloc_global(ixheaace_loudness_info_get_handle_size(), DEFAULT_MEM_ALIGN_8);
709
7.35k
  if (loudness_handle == NULL) {
710
0
    printf("fatal error: libxaac encoder: Memory allocation failed");
711
0
    return -1;
712
0
  }
713
714
7.35k
  err_code = ixheaace_loudness_init_params(loudness_handle, pstr_in_cfg, pstr_out_cfg);
715
716
7.35k
  if (err_code) {
717
1.11k
    free_global(loudness_handle);
718
1.11k
    return -1;
719
1.11k
  }
720
6.24k
  input_size = (pstr_out_cfg->samp_freq / 10) * (pstr_in_cfg->i_channels);
721
6.24k
  WORD16 **samples = 0;
722
6.24k
  samples =
723
6.24k
      (WORD16 **)malloc_global(pstr_in_cfg->i_channels * sizeof(*samples), DEFAULT_MEM_ALIGN_8);
724
6.24k
  if (samples == NULL) {
725
0
    printf("fatal error: libxaac encoder: Memory allocation failed");
726
0
    free_global(loudness_handle);
727
0
    return -1;
728
0
  }
729
16.9k
  for (count = 0; count < pstr_in_cfg->i_channels; count++) {
730
10.7k
    samples[count] = (WORD16 *)malloc_global(
731
10.7k
        (pstr_out_cfg->samp_freq / 10) * sizeof(*samples[count]), DEFAULT_MEM_ALIGN_8);
732
10.7k
    if (samples[count] == NULL) {
733
0
      printf("fatal error: libxaac encoder: Memory allocation failed");
734
0
      while (count) {
735
0
        count--;
736
0
        free_global(samples[count]);
737
0
      }
738
0
      free_global(samples);
739
0
      free_global(loudness_handle);
740
0
      return -1;
741
0
    }
742
10.7k
    memset(samples[count], 0, (pstr_out_cfg->samp_freq / 10) * sizeof(*samples[count]));
743
10.7k
  }
744
6.24k
  count = 0;
745
68.8k
  while (count <= fuzzed_data->remaining_bytes()) {
746
62.5k
    std::vector<WORD8> input_vec = fuzzed_data->ConsumeBytes<WORD8>(input_size);
747
62.5k
    err_code =
748
62.5k
        ia_enhaacplus_enc_pcm_data_read(input_vec, input_size, pstr_in_cfg->i_channels, samples);
749
62.5k
    if (err_code) {
750
0
      for (count = 0; count < pstr_in_cfg->i_channels; count++) {
751
0
        free_global(samples[count]);
752
0
      }
753
0
      free_global(samples);
754
0
      free_global(loudness_handle);
755
0
      return -1;
756
0
    }
757
62.5k
    pstr_in_cfg->measured_loudness = ixheaace_measure_loudness(loudness_handle, samples);
758
62.5k
    count += input_size;
759
62.5k
  }
760
6.24k
  if (pstr_in_cfg->method_def == METHOD_DEFINITION_PROGRAM_LOUDNESS) {
761
23
    pstr_in_cfg->measured_loudness = ixheaace_measure_integrated_loudness(loudness_handle);
762
23
  }
763
16.9k
  for (count = 0; count < pstr_in_cfg->i_channels; count++) {
764
10.7k
    free_global(samples[count]);
765
10.7k
  }
766
6.24k
  free_global(samples);
767
6.24k
  free_global(loudness_handle);
768
6.24k
  return err_code;
769
6.24k
}
770
771
11.6k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
772
11.6k
  FuzzedDataProvider fuzzed_data(data, size);
773
11.6k
  FuzzedDataProvider fuzzed_data_loudness(data, size);
774
775
  /* Error code */
776
11.6k
  IA_ERRORCODE err_code = 0;
777
778
  /* API obj */
779
11.6k
  pVOID pv_ia_process_api_obj;
780
781
11.6k
  pWORD8 pb_inp_buf = NULL;
782
11.6k
  WORD32 input_size = 0;
783
11.6k
  WORD32 read_inp_data = 1;
784
11.6k
  WORD32 num_proc_iterations = 0;
785
786
  /* ******************************************************************/
787
  /* The API config structure                                         */
788
  /* ******************************************************************/
789
790
11.6k
  ixheaace_user_config_struct str_enc_api{};
791
792
11.6k
  ixheaace_input_config *pstr_in_cfg = &str_enc_api.input_config;
793
11.6k
  ixheaace_output_config *pstr_out_cfg = &str_enc_api.output_config;
794
11.6k
  pstr_in_cfg->pv_drc_cfg = malloc_global(sizeof(ia_drc_input_config), DEFAULT_MEM_ALIGN_8);
795
11.6k
  ia_drc_input_config *pstr_drc_cfg = (ia_drc_input_config *)pstr_in_cfg->pv_drc_cfg;
796
11.6k
  memset(pstr_drc_cfg, 0, sizeof(ia_drc_input_config));
797
798
11.6k
  pstr_out_cfg->malloc_xheaace = &malloc_global;
799
11.6k
  pstr_out_cfg->free_xheaace = &free_global;
800
801
  /* ******************************************************************/
802
  /* Parse input configuration parameters                             */
803
  /* ******************************************************************/
804
11.6k
  ixheaace_fuzzer_flag(pstr_in_cfg, pstr_drc_cfg, &fuzzed_data, pstr_in_cfg->i_channels);
805
806
  /*1st pass -> Loudness Measurement */
807
11.6k
  if (pstr_in_cfg->aot == AOT_USAC || pstr_in_cfg->usac_en) {
808
7.35k
    err_code =
809
7.35k
        ixheaace_calculate_loudness_measure(pstr_in_cfg, pstr_out_cfg, &fuzzed_data_loudness);
810
7.35k
    if (err_code) {
811
1.11k
      if (pstr_drc_cfg) {
812
1.11k
        free(pstr_drc_cfg);
813
1.11k
        pstr_drc_cfg = NULL;
814
1.11k
      }
815
      /* Fatal error code */
816
1.11k
      if (err_code & 0x80000000) {
817
1.11k
        ixheaace_delete((pVOID)pstr_out_cfg);
818
1.11k
        return 0;
819
1.11k
      }
820
0
      return -1;
821
1.11k
    }
822
7.35k
  }
823
824
10.5k
  err_code = ixheaace_create((pVOID)pstr_in_cfg, (pVOID)pstr_out_cfg);
825
10.5k
  if (err_code) {
826
2.50k
    if (pstr_drc_cfg) {
827
2.50k
      free(pstr_drc_cfg);
828
2.50k
      pstr_drc_cfg = NULL;
829
2.50k
    }
830
    /* Fatal error code */
831
2.50k
    if (err_code & 0x80000000) {
832
2.20k
      ixheaace_delete((pVOID)pstr_out_cfg);
833
2.20k
      return 0;
834
2.20k
    }
835
2.50k
  }
836
837
8.35k
  pv_ia_process_api_obj = pstr_out_cfg->pv_ia_process_api_obj;
838
8.35k
  pb_inp_buf = (pWORD8)pstr_out_cfg->mem_info_table[IA_MEMTYPE_INPUT].mem_ptr;
839
840
  /* End first part */
841
842
  /* Second part        */
843
  /* Initialize process */
844
  /* Get config params  */
845
846
8.35k
  input_size = pstr_out_cfg->input_size;
847
8.35k
  memset(pb_inp_buf, 0, input_size);
848
849
629k
  while (fuzzed_data.remaining_bytes()) {
850
621k
    if (read_inp_data) {
851
601k
      if (fuzzed_data.ConsumeBool()) {
852
135k
        std::vector<WORD8> input_vec = fuzzed_data.ConsumeBytes<WORD8>(input_size);
853
135k
        if (input_vec.size()) {
854
117k
          memcpy(pb_inp_buf, input_vec.data(), input_vec.size());
855
117k
        }
856
466k
      } else {
857
466k
        memset(pb_inp_buf, fuzzed_data.ConsumeIntegral<WORD8>(), input_size);
858
466k
      }
859
601k
    }
860
621k
    ixheaace_process(pv_ia_process_api_obj, (pVOID)pstr_in_cfg, (pVOID)pstr_out_cfg);
861
621k
    num_proc_iterations++;
862
621k
    if (pstr_out_cfg->i_out_bytes == 0) {
863
20.6k
      read_inp_data = 0;
864
601k
    } else {
865
601k
      read_inp_data = 1;
866
601k
    }
867
    /* Stop processing after 500 frames */
868
621k
    if (num_proc_iterations > 500) break;
869
621k
  }
870
871
8.35k
  ixheaace_delete((pVOID)pstr_out_cfg);
872
873
8.35k
  if (pstr_drc_cfg) {
874
8.04k
    free(pstr_drc_cfg);
875
8.04k
  }
876
8.35k
  return 0;
877
10.5k
}
878
879
/* End ia_main_process() */