Skip to content

Commit fe1ab28

Browse files
author
Timothy B. Terriberry
committed
Validate frame idx when scanning for DRED payload.
Without this check, a DRED extension encoded with an invalid frame number would still be used, potentially with a surprisingly large dred_frame_offset.
1 parent a214a46 commit fe1ab28

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/opus_decoder.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1299,16 +1299,16 @@ static int dred_find_payload(const unsigned char *data, opus_int32 len, const un
12991299
const unsigned char *data0;
13001300
int len0;
13011301
int frame = 0;
1302-
int ret;
1302+
int nb_frames;
13031303
const unsigned char *frames[48];
13041304
opus_int16 size[48];
13051305
int frame_size;
13061306

13071307
*payload = NULL;
13081308
/* Get the padding section of the packet. */
1309-
ret = opus_packet_parse_impl(data, len, 0, NULL, frames, size, NULL, NULL, &data0, &len0);
1310-
if (ret < 0)
1311-
return ret;
1309+
nb_frames = opus_packet_parse_impl(data, len, 0, NULL, frames, size, NULL, NULL, &data0, &len0);
1310+
if (nb_frames < 0)
1311+
return nb_frames;
13121312
frame_size = opus_packet_get_samples_per_frame(data, 48000);
13131313
data = data0;
13141314
len = len0;
@@ -1332,6 +1332,9 @@ static int dred_find_payload(const unsigned char *data, opus_int32 len, const un
13321332
} else {
13331333
frame += data0[1];
13341334
}
1335+
if (frame >= nb_frames) {
1336+
break;
1337+
}
13351338
} else if (id == DRED_EXTENSION_ID)
13361339
{
13371340
const unsigned char *curr_payload;

0 commit comments

Comments
 (0)