Browse Source

atrac1: check output buffer size before decoding

tags/n0.9
Justin Ruggles 13 years ago
parent
commit
33684b9c12
1 changed files with 9 additions and 2 deletions
  1. +9
    -2
      libavcodec/atrac1.c

+ 9
- 2
libavcodec/atrac1.c View File

@@ -276,7 +276,7 @@ static int atrac1_decode_frame(AVCodecContext *avctx, void *data,
const uint8_t *buf = avpkt->data; const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size; int buf_size = avpkt->size;
AT1Ctx *q = avctx->priv_data; AT1Ctx *q = avctx->priv_data;
int ch, ret, i;
int ch, ret, i, out_size;
GetBitContext gb; GetBitContext gb;
float* samples = data; float* samples = data;


@@ -286,6 +286,13 @@ static int atrac1_decode_frame(AVCodecContext *avctx, void *data,
return -1; return -1;
} }


out_size = q->channels * AT1_SU_SAMPLES *
av_get_bytes_per_sample(avctx->sample_fmt);
if (*data_size < out_size) {
av_log(avctx, AV_LOG_ERROR, "Output buffer is too small\n");
return AVERROR(EINVAL);
}

for (ch = 0; ch < q->channels; ch++) { for (ch = 0; ch < q->channels; ch++) {
AT1SUCtx* su = &q->SUs[ch]; AT1SUCtx* su = &q->SUs[ch];


@@ -318,7 +325,7 @@ static int atrac1_decode_frame(AVCodecContext *avctx, void *data,
} }
} }


*data_size = q->channels * AT1_SU_SAMPLES * sizeof(*samples);
*data_size = out_size;
return avctx->block_align; return avctx->block_align;
} }




Loading…
Cancel
Save