History

avcodec/speexdec: Pass and check remaining packets to decode functions

Fixes: out of array access Fixes: 394638693/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_SPEEX_fuzzer-4868142996455424

Michael Niedermayer committed 1 year ago

Commit f6986e71 parent 67040771 file · +9 −7Browse files

Showing the changes to libavcodec (1 of 1 file). Show all

Unified · Split

libavcodec/speexdec.c+9−7
@@ -169,7 +169,7 @@ typedef struct SpeexSubmode { · 168 unmodified lines
169169
170170 typedef struct SpeexMode {
171171 int modeID; /**< ID of the mode */
172− int (*decode)(AVCodecContext *avctx, void *dec, GetBitContext *gb, float *out);
172+ int (*decode)(AVCodecContext *avctx, void *dec, GetBitContext *gb, float *out, int packets_left);
173173 int frame_size; /**< Size of frames used for decoding */
174174 int subframe_size; /**< Size of sub-frames used for decoding */
175175 int lpc_size; /**< Order of LPC filter */
@@ -521,8 +521,8 @@ static const SpeexSubmode wb_submode4 = { · 345 unmodified lines
521521 split_cb_shape_sign_unquant, &split_cb_high, -1.f
522522 };
523523
524−static int nb_decode(AVCodecContext *, void *, GetBitContext *, float *);
525−static int sb_decode(AVCodecContext *, void *, GetBitContext *, float *);
524+static int nb_decode(AVCodecContext *, void *, GetBitContext *, float *, int packets_left);
525+static int sb_decode(AVCodecContext *, void *, GetBitContext *, float *, int packets_left);
526526
527527 static const SpeexMode speex_modes[SPEEX_NB_MODES] = {
528528 {
@@ -867,7 +867,7 @@ static void lsp_to_lpc(const float *freq, float *ak, int lpcrdr) · 338 unmodified lines
867867 }
868868
869869 static int nb_decode(AVCodecContext *avctx, void *ptr_st,
870− GetBitContext *gb, float *out)
870+ GetBitContext *gb, float *out, int packets_left)
871871 {
872872 DecoderState *st = ptr_st;
873873 float ol_gain = 0, ol_pitch_coef = 0, best_pitch_gain = 0, pitch_average = 0;
@@ -1218,7 +1218,7 @@ static void qmf_synth(const float *x1, const float *x2, const float *a, float *y · 344 unmodified lines
12181218 }
12191219
12201220 static int sb_decode(AVCodecContext *avctx, void *ptr_st,
1221− GetBitContext *gb, float *out)
1221+ GetBitContext *gb, float *out, int packets_left)
12221222 {
12231223 SpeexContext *s = avctx->priv_data;
12241224 DecoderState *st = ptr_st;
@@ -1234,9 +1234,11 @@ static int sb_decode(AVCodecContext *avctx, void *ptr_st, · 9 unmodified lines
12341234 mode = st->mode;
12351235
12361236 if (st->modeID > 0) {
1237+ if (packets_left <= 1)
1238+ return AVERROR_INVALIDDATA;
12371239 low_innov_alias = out + st->frame_size;
12381240 s->st[st->modeID - 1].innov_save = low_innov_alias;
1239− ret = speex_modes[st->modeID - 1].decode(avctx, &s->st[st->modeID - 1], gb, out);
1241+ ret = speex_modes[st->modeID - 1].decode(avctx, &s->st[st->modeID - 1], gb, out, packets_left);
12401242 if (ret < 0)
12411243 return ret;
12421244 }
@@ -1559,7 +1561,7 @@ static int speex_decode_frame(AVCodecContext *avctx, AVFrame *frame, · 316 unmodified lines
15591561
15601562 dst = (float *)frame->extended_data[0];
15611563 for (int i = 0; i < frames_per_packet; i++) {
1562− ret = speex_modes[s->mode].decode(avctx, &s->st[s->mode], &s->gb, dst + i * s->frame_size);
1564+ ret = speex_modes[s->mode].decode(avctx, &s->st[s->mode], &s->gb, dst + i * s->frame_size, frames_per_packet - i);
15631565 if (ret < 0)
15641566 return ret;
15651567 if (avctx->ch_layout.nb_channels == 2)

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t