Browse Source

twinvq: check output buffer size before decoding

(cherry picked from commit e53eecd0e7)

Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
tags/n0.8.6
Justin Ruggles Michael Niedermayer 14 years ago
parent
commit
e9de2d98a9
1 changed files with 9 additions and 2 deletions
  1. +9
    -2
      libavcodec/twinvq.c

+ 9
- 2
libavcodec/twinvq.c View File

@@ -822,7 +822,7 @@ static int twin_decode_frame(AVCodecContext * avctx, void *data,
const ModeTab *mtab = tctx->mtab;
float *out = data;
enum FrameType ftype;
int window_type;
int window_type, out_size;
static const enum FrameType wtype_to_ftype_table[] = {
FT_LONG, FT_LONG, FT_SHORT, FT_LONG,
FT_MEDIUM, FT_LONG, FT_LONG, FT_MEDIUM, FT_MEDIUM
@@ -835,6 +835,13 @@ static int twin_decode_frame(AVCodecContext * avctx, void *data,
return buf_size;
}

out_size = mtab->size * avctx->channels *
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);
}

init_get_bits(&gb, buf, buf_size * 8);
skip_bits(&gb, get_bits(&gb, 8));
window_type = get_bits(&gb, WINDOW_TYPE_BITS);
@@ -857,7 +864,7 @@ static int twin_decode_frame(AVCodecContext * avctx, void *data,
return buf_size;
}

*data_size = mtab->size*avctx->channels*4;
*data_size = out_size;

return buf_size;
}


Loading…
Cancel
Save