Coverage Report

Created: 2026-06-07 08:05

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
65.1k
#define MAX_PACKET (1500)
30
static unsigned char out[MAX_PACKET];
31
32
67.0k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
33
67.0k
  FuzzedDataProvider fdp(data, size);
34
35
67.0k
  opus_int32 nb_channels = fdp.ConsumeIntegralInRange(0, 255);
36
67.0k
  const opus_int32 frequency = fdp.PickValueInArray({8, 12, 16, 24, 48
37
67.0k
                                                     ARG_QEXT(96)}) * 1000;
38
67.0k
  int streams = fdp.ConsumeIntegralInRange(0, 255);
39
67.0k
  int coupled_streams = fdp.ConsumeIntegralInRange(0, 255);
40
67.0k
  int frame_size_ms_x2 =
41
67.0k
      fdp.PickValueInArray({5, 10, 20, 40, 80, 120, 160, 200, 240});
42
67.0k
  int frame_size = frame_size_ms_x2 * frequency / 2000;
43
67.0k
  int application =
44
67.0k
      fdp.PickValueInArray({OPUS_APPLICATION_AUDIO, OPUS_APPLICATION_VOIP,
45
67.0k
                            OPUS_APPLICATION_RESTRICTED_LOWDELAY});
46
47
48
67.0k
  int err = OPUS_OK;
49
67.0k
    int mapping_family = fdp.PickValueInArray({0, 1, 2, 3, 255});
50
67.0k
  OpusProjectionEncoder *enc = opus_projection_ambisonics_encoder_create(
51
67.0k
        frequency, nb_channels, mapping_family, &streams, &coupled_streams,
52
67.0k
        application, &err);
53
54
67.0k
  if (err != OPUS_OK || enc == NULL) {
55
448
    opus_projection_encoder_destroy(enc);
56
448
    return 0;
57
448
  }
58
59
66.6k
  opus_projection_encoder_ctl(
60
66.6k
      enc, OPUS_SET_COMPLEXITY(fdp.ConsumeIntegralInRange(0, 10)));
61
66.6k
  opus_projection_encoder_ctl(enc, OPUS_SET_VBR(fdp.ConsumeBool()));
62
66.6k
  opus_projection_encoder_ctl(enc, OPUS_SET_VBR_CONSTRAINT(fdp.ConsumeBool()));
63
66.6k
  opus_projection_encoder_ctl(
64
66.6k
      enc, OPUS_SET_FORCE_CHANNELS(fdp.PickValueInArray({OPUS_AUTO, 1, 2})));
65
66.6k
  opus_projection_encoder_ctl(
66
66.6k
      enc, OPUS_SET_MAX_BANDWIDTH(fdp.PickValueInArray(
67
66.6k
               {OPUS_BANDWIDTH_NARROWBAND, OPUS_BANDWIDTH_MEDIUMBAND,
68
66.6k
                OPUS_BANDWIDTH_WIDEBAND, OPUS_BANDWIDTH_SUPERWIDEBAND,
69
66.6k
                OPUS_BANDWIDTH_FULLBAND})));
70
66.6k
  opus_projection_encoder_ctl(enc, OPUS_SET_INBAND_FEC(fdp.ConsumeBool()));
71
66.6k
  opus_projection_encoder_ctl(
72
66.6k
      enc, OPUS_SET_PACKET_LOSS_PERC(fdp.ConsumeIntegralInRange(0, 100)));
73
66.6k
  opus_projection_encoder_ctl(enc, OPUS_SET_DTX(fdp.ConsumeBool()));
74
66.6k
  opus_projection_encoder_ctl(
75
66.6k
      enc, OPUS_SET_LSB_DEPTH(fdp.ConsumeIntegralInRange(8, 24)));
76
66.6k
  opus_projection_encoder_ctl(
77
66.6k
      enc, OPUS_SET_PREDICTION_DISABLED((fdp.ConsumeBool())));
78
66.6k
  opus_projection_encoder_ctl(
79
66.6k
      enc, OPUS_SET_SIGNAL(fdp.PickValueInArray(
80
66.6k
               {OPUS_AUTO, OPUS_SIGNAL_VOICE, OPUS_SIGNAL_MUSIC})));
81
66.6k
  opus_projection_encoder_ctl(
82
66.6k
      enc, OPUS_SET_PHASE_INVERSION_DISABLED(((fdp.ConsumeBool()))));
83
84
66.6k
  const int pcm_size = sizeof(opus_int16) * frame_size * nb_channels;
85
66.6k
  opus_int16 *pcm = (opus_int16 *)opus_alloc(pcm_size);
86
66.6k
  if (pcm == NULL) {
87
0
    opus_projection_encoder_destroy(enc);
88
0
    return 0;
89
0
  }
90
66.6k
  memset(pcm, 0, pcm_size);
91
92
66.6k
  if (pcm_size == fdp.ConsumeData(pcm, pcm_size)) {
93
65.1k
    const int len =
94
65.1k
        opus_projection_encode(enc, pcm, frame_size, out, MAX_PACKET);
95
65.1k
    (void)len;
96
65.1k
  }
97
98
66.6k
  opus_free(pcm);
99
66.6k
  opus_projection_encoder_destroy(enc);
100
101
66.6k
  return 0;
102
66.6k
}
LLVMFuzzerTestOneInput
Line
Count
Source
32
33.5k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
33
33.5k
  FuzzedDataProvider fdp(data, size);
34
35
33.5k
  opus_int32 nb_channels = fdp.ConsumeIntegralInRange(0, 255);
36
33.5k
  const opus_int32 frequency = fdp.PickValueInArray({8, 12, 16, 24, 48
37
33.5k
                                                     ARG_QEXT(96)}) * 1000;
38
33.5k
  int streams = fdp.ConsumeIntegralInRange(0, 255);
39
33.5k
  int coupled_streams = fdp.ConsumeIntegralInRange(0, 255);
40
33.5k
  int frame_size_ms_x2 =
41
33.5k
      fdp.PickValueInArray({5, 10, 20, 40, 80, 120, 160, 200, 240});
42
33.5k
  int frame_size = frame_size_ms_x2 * frequency / 2000;
43
33.5k
  int application =
44
33.5k
      fdp.PickValueInArray({OPUS_APPLICATION_AUDIO, OPUS_APPLICATION_VOIP,
45
33.5k
                            OPUS_APPLICATION_RESTRICTED_LOWDELAY});
46
47
48
33.5k
  int err = OPUS_OK;
49
33.5k
    int mapping_family = fdp.PickValueInArray({0, 1, 2, 3, 255});
50
33.5k
  OpusProjectionEncoder *enc = opus_projection_ambisonics_encoder_create(
51
33.5k
        frequency, nb_channels, mapping_family, &streams, &coupled_streams,
52
33.5k
        application, &err);
53
54
33.5k
  if (err != OPUS_OK || enc == NULL) {
55
224
    opus_projection_encoder_destroy(enc);
56
224
    return 0;
57
224
  }
58
59
33.3k
  opus_projection_encoder_ctl(
60
33.3k
      enc, OPUS_SET_COMPLEXITY(fdp.ConsumeIntegralInRange(0, 10)));
61
33.3k
  opus_projection_encoder_ctl(enc, OPUS_SET_VBR(fdp.ConsumeBool()));
62
33.3k
  opus_projection_encoder_ctl(enc, OPUS_SET_VBR_CONSTRAINT(fdp.ConsumeBool()));
63
33.3k
  opus_projection_encoder_ctl(
64
33.3k
      enc, OPUS_SET_FORCE_CHANNELS(fdp.PickValueInArray({OPUS_AUTO, 1, 2})));
65
33.3k
  opus_projection_encoder_ctl(
66
33.3k
      enc, OPUS_SET_MAX_BANDWIDTH(fdp.PickValueInArray(
67
33.3k
               {OPUS_BANDWIDTH_NARROWBAND, OPUS_BANDWIDTH_MEDIUMBAND,
68
33.3k
                OPUS_BANDWIDTH_WIDEBAND, OPUS_BANDWIDTH_SUPERWIDEBAND,
69
33.3k
                OPUS_BANDWIDTH_FULLBAND})));
70
33.3k
  opus_projection_encoder_ctl(enc, OPUS_SET_INBAND_FEC(fdp.ConsumeBool()));
71
33.3k
  opus_projection_encoder_ctl(
72
33.3k
      enc, OPUS_SET_PACKET_LOSS_PERC(fdp.ConsumeIntegralInRange(0, 100)));
73
33.3k
  opus_projection_encoder_ctl(enc, OPUS_SET_DTX(fdp.ConsumeBool()));
74
33.3k
  opus_projection_encoder_ctl(
75
33.3k
      enc, OPUS_SET_LSB_DEPTH(fdp.ConsumeIntegralInRange(8, 24)));
76
33.3k
  opus_projection_encoder_ctl(
77
33.3k
      enc, OPUS_SET_PREDICTION_DISABLED((fdp.ConsumeBool())));
78
33.3k
  opus_projection_encoder_ctl(
79
33.3k
      enc, OPUS_SET_SIGNAL(fdp.PickValueInArray(
80
33.3k
               {OPUS_AUTO, OPUS_SIGNAL_VOICE, OPUS_SIGNAL_MUSIC})));
81
33.3k
  opus_projection_encoder_ctl(
82
33.3k
      enc, OPUS_SET_PHASE_INVERSION_DISABLED(((fdp.ConsumeBool()))));
83
84
33.3k
  const int pcm_size = sizeof(opus_int16) * frame_size * nb_channels;
85
33.3k
  opus_int16 *pcm = (opus_int16 *)opus_alloc(pcm_size);
86
33.3k
  if (pcm == NULL) {
87
0
    opus_projection_encoder_destroy(enc);
88
0
    return 0;
89
0
  }
90
33.3k
  memset(pcm, 0, pcm_size);
91
92
33.3k
  if (pcm_size == fdp.ConsumeData(pcm, pcm_size)) {
93
32.5k
    const int len =
94
32.5k
        opus_projection_encode(enc, pcm, frame_size, out, MAX_PACKET);
95
32.5k
    (void)len;
96
32.5k
  }
97
98
33.3k
  opus_free(pcm);
99
33.3k
  opus_projection_encoder_destroy(enc);
100
101
33.3k
  return 0;
102
33.3k
}
LLVMFuzzerTestOneInput
Line
Count
Source
32
33.5k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) {
33
33.5k
  FuzzedDataProvider fdp(data, size);
34
35
33.5k
  opus_int32 nb_channels = fdp.ConsumeIntegralInRange(0, 255);
36
33.5k
  const opus_int32 frequency = fdp.PickValueInArray({8, 12, 16, 24, 48
37
33.5k
                                                     ARG_QEXT(96)}) * 1000;
38
33.5k
  int streams = fdp.ConsumeIntegralInRange(0, 255);
39
33.5k
  int coupled_streams = fdp.ConsumeIntegralInRange(0, 255);
40
33.5k
  int frame_size_ms_x2 =
41
33.5k
      fdp.PickValueInArray({5, 10, 20, 40, 80, 120, 160, 200, 240});
42
33.5k
  int frame_size = frame_size_ms_x2 * frequency / 2000;
43
33.5k
  int application =
44
33.5k
      fdp.PickValueInArray({OPUS_APPLICATION_AUDIO, OPUS_APPLICATION_VOIP,
45
33.5k
                            OPUS_APPLICATION_RESTRICTED_LOWDELAY});
46
47
48
33.5k
  int err = OPUS_OK;
49
33.5k
    int mapping_family = fdp.PickValueInArray({0, 1, 2, 3, 255});
50
33.5k
  OpusProjectionEncoder *enc = opus_projection_ambisonics_encoder_create(
51
33.5k
        frequency, nb_channels, mapping_family, &streams, &coupled_streams,
52
33.5k
        application, &err);
53
54
33.5k
  if (err != OPUS_OK || enc == NULL) {
55
224
    opus_projection_encoder_destroy(enc);
56
224
    return 0;
57
224
  }
58
59
33.3k
  opus_projection_encoder_ctl(
60
33.3k
      enc, OPUS_SET_COMPLEXITY(fdp.ConsumeIntegralInRange(0, 10)));
61
33.3k
  opus_projection_encoder_ctl(enc, OPUS_SET_VBR(fdp.ConsumeBool()));
62
33.3k
  opus_projection_encoder_ctl(enc, OPUS_SET_VBR_CONSTRAINT(fdp.ConsumeBool()));
63
33.3k
  opus_projection_encoder_ctl(
64
33.3k
      enc, OPUS_SET_FORCE_CHANNELS(fdp.PickValueInArray({OPUS_AUTO, 1, 2})));
65
33.3k
  opus_projection_encoder_ctl(
66
33.3k
      enc, OPUS_SET_MAX_BANDWIDTH(fdp.PickValueInArray(
67
33.3k
               {OPUS_BANDWIDTH_NARROWBAND, OPUS_BANDWIDTH_MEDIUMBAND,
68
33.3k
                OPUS_BANDWIDTH_WIDEBAND, OPUS_BANDWIDTH_SUPERWIDEBAND,
69
33.3k
                OPUS_BANDWIDTH_FULLBAND})));
70
33.3k
  opus_projection_encoder_ctl(enc, OPUS_SET_INBAND_FEC(fdp.ConsumeBool()));
71
33.3k
  opus_projection_encoder_ctl(
72
33.3k
      enc, OPUS_SET_PACKET_LOSS_PERC(fdp.ConsumeIntegralInRange(0, 100)));
73
33.3k
  opus_projection_encoder_ctl(enc, OPUS_SET_DTX(fdp.ConsumeBool()));
74
33.3k
  opus_projection_encoder_ctl(
75
33.3k
      enc, OPUS_SET_LSB_DEPTH(fdp.ConsumeIntegralInRange(8, 24)));
76
33.3k
  opus_projection_encoder_ctl(
77
33.3k
      enc, OPUS_SET_PREDICTION_DISABLED((fdp.ConsumeBool())));
78
33.3k
  opus_projection_encoder_ctl(
79
33.3k
      enc, OPUS_SET_SIGNAL(fdp.PickValueInArray(
80
33.3k
               {OPUS_AUTO, OPUS_SIGNAL_VOICE, OPUS_SIGNAL_MUSIC})));
81
33.3k
  opus_projection_encoder_ctl(
82
33.3k
      enc, OPUS_SET_PHASE_INVERSION_DISABLED(((fdp.ConsumeBool()))));
83
84
33.3k
  const int pcm_size = sizeof(opus_int16) * frame_size * nb_channels;
85
33.3k
  opus_int16 *pcm = (opus_int16 *)opus_alloc(pcm_size);
86
33.3k
  if (pcm == NULL) {
87
0
    opus_projection_encoder_destroy(enc);
88
0
    return 0;
89
0
  }
90
33.3k
  memset(pcm, 0, pcm_size);
91
92
33.3k
  if (pcm_size == fdp.ConsumeData(pcm, pcm_size)) {
93
32.5k
    const int len =
94
32.5k
        opus_projection_encode(enc, pcm, frame_size, out, MAX_PACKET);
95
32.5k
    (void)len;
96
32.5k
  }
97
98
33.3k
  opus_free(pcm);
99
33.3k
  opus_projection_encoder_destroy(enc);
100
101
33.3k
  return 0;
102
33.3k
}