Coverage Report

Created: 2025-11-16 07:23

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/opus/tests/opus_projection_encoder_fuzzer.cc
Line
Count
Source
1
// Copyright 2021 Google LLC
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
//      http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14
15
#include <fuzzer/FuzzedDataProvider.h>
16
#include <math.h>
17
#include <stdint.h>
18
#include <stdlib.h>
19
#include <string.h>
20
21
#include "opus.h"
22
#include "opus_defines.h"
23
#include "opus_projection.h"
24
#include "opus_types.h"
25
#include "../celt/os_support.h"
26
27
#include "opus_ossfuzz_utils.h"
28
29
60.9k
#define MAX_PACKET (1500)
30
static unsigned char out[MAX_PACKET];
31
32
62.7k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
33
62.7k
  FuzzedDataProvider fdp(data, size);
34
35
62.7k
  opus_int32 nb_channels = fdp.ConsumeIntegralInRange(0, 255);
36
62.7k
  const opus_int32 frequency = fdp.PickValueInArray({8, 12, 16, 24, 48
37
62.7k
                                                     ARG_QEXT(96)}) * 1000;
38
62.7k
  int streams = fdp.ConsumeIntegralInRange(0, 255);
39
62.7k
  int coupled_streams = fdp.ConsumeIntegralInRange(0, 255);
40
62.7k
  int frame_size_ms_x2 =
41
62.7k
      fdp.PickValueInArray({5, 10, 20, 40, 80, 120, 160, 200, 240});
42
62.7k
  int frame_size = frame_size_ms_x2 * frequency / 2000;
43
62.7k
  int application =
44
62.7k
      fdp.PickValueInArray({OPUS_APPLICATION_AUDIO, OPUS_APPLICATION_VOIP,
45
62.7k
                            OPUS_APPLICATION_RESTRICTED_LOWDELAY});
46
47
48
62.7k
  int err = OPUS_OK;
49
62.7k
    int mapping_family = fdp.PickValueInArray({0, 1, 2, 3, 255});
50
62.7k
  OpusProjectionEncoder *enc = opus_projection_ambisonics_encoder_create(
51
62.7k
        frequency, nb_channels, mapping_family, &streams, &coupled_streams,
52
62.7k
        application, &err);
53
54
62.7k
  if (err != OPUS_OK || enc == NULL) {
55
350
    opus_projection_encoder_destroy(enc);
56
350
    return 0;
57
350
  }
58
59
62.4k
  opus_projection_encoder_ctl(
60
62.4k
      enc, OPUS_SET_COMPLEXITY(fdp.ConsumeIntegralInRange(0, 10)));
61
62.4k
  opus_projection_encoder_ctl(enc, OPUS_SET_VBR(fdp.ConsumeBool()));
62
62.4k
  opus_projection_encoder_ctl(enc, OPUS_SET_VBR_CONSTRAINT(fdp.ConsumeBool()));
63
62.4k
  opus_projection_encoder_ctl(
64
62.4k
      enc, OPUS_SET_FORCE_CHANNELS(fdp.PickValueInArray({OPUS_AUTO, 1, 2})));
65
62.4k
  opus_projection_encoder_ctl(
66
62.4k
      enc, OPUS_SET_MAX_BANDWIDTH(fdp.PickValueInArray(
67
62.4k
               {OPUS_BANDWIDTH_NARROWBAND, OPUS_BANDWIDTH_MEDIUMBAND,
68
62.4k
                OPUS_BANDWIDTH_WIDEBAND, OPUS_BANDWIDTH_SUPERWIDEBAND,
69
62.4k
                OPUS_BANDWIDTH_FULLBAND})));
70
62.4k
  opus_projection_encoder_ctl(enc, OPUS_SET_INBAND_FEC(fdp.ConsumeBool()));
71
62.4k
  opus_projection_encoder_ctl(
72
62.4k
      enc, OPUS_SET_PACKET_LOSS_PERC(fdp.ConsumeIntegralInRange(0, 100)));
73
62.4k
  opus_projection_encoder_ctl(enc, OPUS_SET_DTX(fdp.ConsumeBool()));
74
62.4k
  opus_projection_encoder_ctl(
75
62.4k
      enc, OPUS_SET_LSB_DEPTH(fdp.ConsumeIntegralInRange(8, 24)));
76
62.4k
  opus_projection_encoder_ctl(
77
62.4k
      enc, OPUS_SET_PREDICTION_DISABLED((fdp.ConsumeBool())));
78
62.4k
  opus_projection_encoder_ctl(
79
62.4k
      enc, OPUS_SET_SIGNAL(fdp.PickValueInArray(
80
62.4k
               {OPUS_AUTO, OPUS_SIGNAL_VOICE, OPUS_SIGNAL_MUSIC})));
81
62.4k
  opus_projection_encoder_ctl(
82
62.4k
      enc, OPUS_SET_PHASE_INVERSION_DISABLED(((fdp.ConsumeBool()))));
83
84
62.4k
  const int pcm_size = sizeof(opus_int16) * frame_size * nb_channels;
85
62.4k
  opus_int16 *pcm = (opus_int16 *)opus_alloc(pcm_size);
86
62.4k
  if (pcm == NULL) {
87
0
    opus_projection_encoder_destroy(enc);
88
0
    return 0;
89
0
  }
90
62.4k
  memset(pcm, 0, pcm_size);
91
92
62.4k
  if (pcm_size == fdp.ConsumeData(pcm, pcm_size)) {
93
60.9k
    const int len =
94
60.9k
        opus_projection_encode(enc, pcm, frame_size, out, MAX_PACKET);
95
60.9k
    (void)len;
96
60.9k
  }
97
98
62.4k
  opus_free(pcm);
99
62.4k
  opus_projection_encoder_destroy(enc);
100
101
62.4k
  return 0;
102
62.4k
}
LLVMFuzzerTestOneInput
Line
Count
Source
32
31.3k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
33
31.3k
  FuzzedDataProvider fdp(data, size);
34
35
31.3k
  opus_int32 nb_channels = fdp.ConsumeIntegralInRange(0, 255);
36
31.3k
  const opus_int32 frequency = fdp.PickValueInArray({8, 12, 16, 24, 48
37
31.3k
                                                     ARG_QEXT(96)}) * 1000;
38
31.3k
  int streams = fdp.ConsumeIntegralInRange(0, 255);
39
31.3k
  int coupled_streams = fdp.ConsumeIntegralInRange(0, 255);
40
31.3k
  int frame_size_ms_x2 =
41
31.3k
      fdp.PickValueInArray({5, 10, 20, 40, 80, 120, 160, 200, 240});
42
31.3k
  int frame_size = frame_size_ms_x2 * frequency / 2000;
43
31.3k
  int application =
44
31.3k
      fdp.PickValueInArray({OPUS_APPLICATION_AUDIO, OPUS_APPLICATION_VOIP,
45
31.3k
                            OPUS_APPLICATION_RESTRICTED_LOWDELAY});
46
47
48
31.3k
  int err = OPUS_OK;
49
31.3k
    int mapping_family = fdp.PickValueInArray({0, 1, 2, 3, 255});
50
31.3k
  OpusProjectionEncoder *enc = opus_projection_ambisonics_encoder_create(
51
31.3k
        frequency, nb_channels, mapping_family, &streams, &coupled_streams,
52
31.3k
        application, &err);
53
54
31.3k
  if (err != OPUS_OK || enc == NULL) {
55
175
    opus_projection_encoder_destroy(enc);
56
175
    return 0;
57
175
  }
58
59
31.2k
  opus_projection_encoder_ctl(
60
31.2k
      enc, OPUS_SET_COMPLEXITY(fdp.ConsumeIntegralInRange(0, 10)));
61
31.2k
  opus_projection_encoder_ctl(enc, OPUS_SET_VBR(fdp.ConsumeBool()));
62
31.2k
  opus_projection_encoder_ctl(enc, OPUS_SET_VBR_CONSTRAINT(fdp.ConsumeBool()));
63
31.2k
  opus_projection_encoder_ctl(
64
31.2k
      enc, OPUS_SET_FORCE_CHANNELS(fdp.PickValueInArray({OPUS_AUTO, 1, 2})));
65
31.2k
  opus_projection_encoder_ctl(
66
31.2k
      enc, OPUS_SET_MAX_BANDWIDTH(fdp.PickValueInArray(
67
31.2k
               {OPUS_BANDWIDTH_NARROWBAND, OPUS_BANDWIDTH_MEDIUMBAND,
68
31.2k
                OPUS_BANDWIDTH_WIDEBAND, OPUS_BANDWIDTH_SUPERWIDEBAND,
69
31.2k
                OPUS_BANDWIDTH_FULLBAND})));
70
31.2k
  opus_projection_encoder_ctl(enc, OPUS_SET_INBAND_FEC(fdp.ConsumeBool()));
71
31.2k
  opus_projection_encoder_ctl(
72
31.2k
      enc, OPUS_SET_PACKET_LOSS_PERC(fdp.ConsumeIntegralInRange(0, 100)));
73
31.2k
  opus_projection_encoder_ctl(enc, OPUS_SET_DTX(fdp.ConsumeBool()));
74
31.2k
  opus_projection_encoder_ctl(
75
31.2k
      enc, OPUS_SET_LSB_DEPTH(fdp.ConsumeIntegralInRange(8, 24)));
76
31.2k
  opus_projection_encoder_ctl(
77
31.2k
      enc, OPUS_SET_PREDICTION_DISABLED((fdp.ConsumeBool())));
78
31.2k
  opus_projection_encoder_ctl(
79
31.2k
      enc, OPUS_SET_SIGNAL(fdp.PickValueInArray(
80
31.2k
               {OPUS_AUTO, OPUS_SIGNAL_VOICE, OPUS_SIGNAL_MUSIC})));
81
31.2k
  opus_projection_encoder_ctl(
82
31.2k
      enc, OPUS_SET_PHASE_INVERSION_DISABLED(((fdp.ConsumeBool()))));
83
84
31.2k
  const int pcm_size = sizeof(opus_int16) * frame_size * nb_channels;
85
31.2k
  opus_int16 *pcm = (opus_int16 *)opus_alloc(pcm_size);
86
31.2k
  if (pcm == NULL) {
87
0
    opus_projection_encoder_destroy(enc);
88
0
    return 0;
89
0
  }
90
31.2k
  memset(pcm, 0, pcm_size);
91
92
31.2k
  if (pcm_size == fdp.ConsumeData(pcm, pcm_size)) {
93
30.4k
    const int len =
94
30.4k
        opus_projection_encode(enc, pcm, frame_size, out, MAX_PACKET);
95
30.4k
    (void)len;
96
30.4k
  }
97
98
31.2k
  opus_free(pcm);
99
31.2k
  opus_projection_encoder_destroy(enc);
100
101
31.2k
  return 0;
102
31.2k
}
LLVMFuzzerTestOneInput
Line
Count
Source
32
31.3k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
33
31.3k
  FuzzedDataProvider fdp(data, size);
34
35
31.3k
  opus_int32 nb_channels = fdp.ConsumeIntegralInRange(0, 255);
36
31.3k
  const opus_int32 frequency = fdp.PickValueInArray({8, 12, 16, 24, 48
37
31.3k
                                                     ARG_QEXT(96)}) * 1000;
38
31.3k
  int streams = fdp.ConsumeIntegralInRange(0, 255);
39
31.3k
  int coupled_streams = fdp.ConsumeIntegralInRange(0, 255);
40
31.3k
  int frame_size_ms_x2 =
41
31.3k
      fdp.PickValueInArray({5, 10, 20, 40, 80, 120, 160, 200, 240});
42
31.3k
  int frame_size = frame_size_ms_x2 * frequency / 2000;
43
31.3k
  int application =
44
31.3k
      fdp.PickValueInArray({OPUS_APPLICATION_AUDIO, OPUS_APPLICATION_VOIP,
45
31.3k
                            OPUS_APPLICATION_RESTRICTED_LOWDELAY});
46
47
48
31.3k
  int err = OPUS_OK;
49
31.3k
    int mapping_family = fdp.PickValueInArray({0, 1, 2, 3, 255});
50
31.3k
  OpusProjectionEncoder *enc = opus_projection_ambisonics_encoder_create(
51
31.3k
        frequency, nb_channels, mapping_family, &streams, &coupled_streams,
52
31.3k
        application, &err);
53
54
31.3k
  if (err != OPUS_OK || enc == NULL) {
55
175
    opus_projection_encoder_destroy(enc);
56
175
    return 0;
57
175
  }
58
59
31.2k
  opus_projection_encoder_ctl(
60
31.2k
      enc, OPUS_SET_COMPLEXITY(fdp.ConsumeIntegralInRange(0, 10)));
61
31.2k
  opus_projection_encoder_ctl(enc, OPUS_SET_VBR(fdp.ConsumeBool()));
62
31.2k
  opus_projection_encoder_ctl(enc, OPUS_SET_VBR_CONSTRAINT(fdp.ConsumeBool()));
63
31.2k
  opus_projection_encoder_ctl(
64
31.2k
      enc, OPUS_SET_FORCE_CHANNELS(fdp.PickValueInArray({OPUS_AUTO, 1, 2})));
65
31.2k
  opus_projection_encoder_ctl(
66
31.2k
      enc, OPUS_SET_MAX_BANDWIDTH(fdp.PickValueInArray(
67
31.2k
               {OPUS_BANDWIDTH_NARROWBAND, OPUS_BANDWIDTH_MEDIUMBAND,
68
31.2k
                OPUS_BANDWIDTH_WIDEBAND, OPUS_BANDWIDTH_SUPERWIDEBAND,
69
31.2k
                OPUS_BANDWIDTH_FULLBAND})));
70
31.2k
  opus_projection_encoder_ctl(enc, OPUS_SET_INBAND_FEC(fdp.ConsumeBool()));
71
31.2k
  opus_projection_encoder_ctl(
72
31.2k
      enc, OPUS_SET_PACKET_LOSS_PERC(fdp.ConsumeIntegralInRange(0, 100)));
73
31.2k
  opus_projection_encoder_ctl(enc, OPUS_SET_DTX(fdp.ConsumeBool()));
74
31.2k
  opus_projection_encoder_ctl(
75
31.2k
      enc, OPUS_SET_LSB_DEPTH(fdp.ConsumeIntegralInRange(8, 24)));
76
31.2k
  opus_projection_encoder_ctl(
77
31.2k
      enc, OPUS_SET_PREDICTION_DISABLED((fdp.ConsumeBool())));
78
31.2k
  opus_projection_encoder_ctl(
79
31.2k
      enc, OPUS_SET_SIGNAL(fdp.PickValueInArray(
80
31.2k
               {OPUS_AUTO, OPUS_SIGNAL_VOICE, OPUS_SIGNAL_MUSIC})));
81
31.2k
  opus_projection_encoder_ctl(
82
31.2k
      enc, OPUS_SET_PHASE_INVERSION_DISABLED(((fdp.ConsumeBool()))));
83
84
31.2k
  const int pcm_size = sizeof(opus_int16) * frame_size * nb_channels;
85
31.2k
  opus_int16 *pcm = (opus_int16 *)opus_alloc(pcm_size);
86
31.2k
  if (pcm == NULL) {
87
0
    opus_projection_encoder_destroy(enc);
88
0
    return 0;
89
0
  }
90
31.2k
  memset(pcm, 0, pcm_size);
91
92
31.2k
  if (pcm_size == fdp.ConsumeData(pcm, pcm_size)) {
93
30.4k
    const int len =
94
30.4k
        opus_projection_encode(enc, pcm, frame_size, out, MAX_PACKET);
95
30.4k
    (void)len;
96
30.4k
  }
97
98
31.2k
  opus_free(pcm);
99
31.2k
  opus_projection_encoder_destroy(enc);
100
101
31.2k
  return 0;
102
31.2k
}