Skip to content

Commit c40f946

Browse files
committed
Fix int overflow in tone_detect() for stereo
1 parent c5a745b commit c40f946

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

celt/celt_encoder.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1370,7 +1370,7 @@ static opus_val16 tone_detect(const celt_sig *in, int CC, int N, opus_val32 *ton
13701370
ALLOC(x, N, opus_val16);
13711371
/* Shift by SIG_SHIFT+2 (+3 for stereo) to account for HF gain of the preemphasis filter. */
13721372
if (CC==2) {
1373-
for (i=0;i<N;i++) x[i] = PSHR32(ADD32(in[i], in[i+N]), SIG_SHIFT+3);
1373+
for (i=0;i<N;i++) x[i] = PSHR32(ADD32(SHR32(in[i], 1), SHR32(in[i+N], 1)), SIG_SHIFT+2);
13741374
} else {
13751375
for (i=0;i<N;i++) x[i] = PSHR32(in[i], SIG_SHIFT+2);
13761376
}

tests/opus_encode_regressions.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1160,6 +1160,44 @@ int projection_overflow(void)
11601160
return 0;
11611161
}
11621162

1163+
int projection_overflow4(void)
1164+
{
1165+
OpusProjectionEncoder *enc;
1166+
int err;
1167+
unsigned char data[1000];
1168+
int data_len;
1169+
int streams;
1170+
int coupled_streams;
1171+
static const short pcm[480*36] =
1172+
{
1173+
5760, -3050, -25, 1, -6144,-32583,-32640,-32641,-32640,
1174+
-32640,-30080,-32640,-32640,-32384,-32640,-32640,-32640,-32640,
1175+
-32640,-21984,-15446,-32640,-32640,-32513,-32640,-18048, 2944,
1176+
-26624, -1, 32767,-15105, 12031, 0, 32639, -2593, 16,
1177+
-8182, 3858, 3855, 3855, 3855, 3855, 3855, 0, 0,
1178+
3855, 3855, 3855, 3855, 176, 32512, 176, 4608, 32732,
1179+
-1, 8704, -2896, -2828, 244, 15104,-27775,-18049, 2944,
1180+
-26624, -1, -7937, -9426, 25443,-18058, 2944, 27648, 204,
1181+
-2289, -1025, 32767, -8449, 16384, 13312, 20852, -34, 64,
1182+
29760, 4096, 116, 4096, 2560, 736, 2896, 2781, 25610,
1183+
-32717, 8970,-22006, 12000, 31097, 31097, 31157, 25465, 8291,
1184+
-21846,-21821, -6742, 12000, 0, 32767, -514, 20320, 20320,
1185+
20328, 20297,-32640,-32640,-21075,-21111,-13139,-32640,-32640,
1186+
-32640,-32640,-32640,-32640,-32640,-32640,-32640,-32640,-27520,
1187+
-32640,-32640,-32640,-32640,-32640,-32640,-32640,-32640,-32640,
1188+
-32640,-32640,-32640,-32640,-32640,-32640,-32513,-32640,-18048
1189+
};
1190+
1191+
enc = opus_projection_ambisonics_encoder_create(96000, 36, 3, &streams,
1192+
&coupled_streams, OPUS_APPLICATION_AUDIO, &err);
1193+
opus_projection_encoder_ctl(enc, OPUS_SET_QEXT(1));
1194+
opus_projection_encoder_ctl(enc, OPUS_SET_BITRATE(256000));
1195+
data_len = opus_projection_encode(enc, pcm, 480, data, 1000);
1196+
opus_test_assert(data_len > 0 && data_len <= 1000);
1197+
1198+
opus_projection_encoder_destroy(enc);
1199+
return 0;
1200+
}
11631201

11641202
#ifdef ENABLE_QEXT
11651203
int qext_repacketize_fail(void)
@@ -1253,6 +1291,7 @@ void regression_test(void)
12531291
projection_overflow3();
12541292
#endif
12551293
projection_overflow();
1294+
projection_overflow4();
12561295
#ifdef ENABLE_QEXT
12571296
qext_repacketize_fail();
12581297
qext_stereo_overflow();

0 commit comments

Comments
 (0)