Commit 6063f012 authored by Michael Niedermayer's avatar Michael Niedermayer

Merge commit '9e7b62f0'

* commit '9e7b62f0':
  twinvq: set block align for codecs and use it in size checks
Merged-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parents e43c672b 9e7b62f0
...@@ -170,12 +170,6 @@ static int metasound_read_bitstream(AVCodecContext *avctx, TwinVQContext *tctx, ...@@ -170,12 +170,6 @@ static int metasound_read_bitstream(AVCodecContext *avctx, TwinVQContext *tctx,
GetBitContext gb; GetBitContext gb;
int i, j, k; int i, j, k;
if (buf_size * 8 < avctx->bit_rate * mtab->size / avctx->sample_rate) {
av_log(avctx, AV_LOG_ERROR,
"Frame too small (%d bytes). Truncated file?\n", buf_size);
return AVERROR(EINVAL);
}
init_get_bits(&gb, buf, buf_size * 8); init_get_bits(&gb, buf, buf_size * 8);
bits->window_type = get_bits(&gb, TWINVQ_WINDOW_TYPE_BITS); bits->window_type = get_bits(&gb, TWINVQ_WINDOW_TYPE_BITS);
...@@ -323,6 +317,9 @@ static av_cold int metasound_decode_init(AVCodecContext *avctx) ...@@ -323,6 +317,9 @@ static av_cold int metasound_decode_init(AVCodecContext *avctx)
return AVERROR(ENOSYS); return AVERROR(ENOSYS);
} }
avctx->block_align = (avctx->bit_rate * tctx->mtab->size
/ avctx->sample_rate + 7) / 8;
tctx->codec = TWINVQ_CODEC_METASOUND; tctx->codec = TWINVQ_CODEC_METASOUND;
tctx->read_bitstream = metasound_read_bitstream; tctx->read_bitstream = metasound_read_bitstream;
tctx->dec_bark_env = dec_bark_env; tctx->dec_bark_env = dec_bark_env;
......
...@@ -489,6 +489,12 @@ int ff_twinvq_decode_frame(AVCodecContext *avctx, void *data, ...@@ -489,6 +489,12 @@ int ff_twinvq_decode_frame(AVCodecContext *avctx, void *data,
out = (float **)frame->extended_data; out = (float **)frame->extended_data;
} }
if (buf_size < avctx->block_align) {
av_log(avctx, AV_LOG_ERROR,
"Frame too small (%d bytes). Truncated file?\n", buf_size);
return AVERROR(EINVAL);
}
if ((ret = tctx->read_bitstream(avctx, tctx, buf, buf_size)) < 0) if ((ret = tctx->read_bitstream(avctx, tctx, buf, buf_size)) < 0)
return ret; return ret;
...@@ -506,7 +512,7 @@ int ff_twinvq_decode_frame(AVCodecContext *avctx, void *data, ...@@ -506,7 +512,7 @@ int ff_twinvq_decode_frame(AVCodecContext *avctx, void *data,
*got_frame_ptr = 1; *got_frame_ptr = 1;
return buf_size; return avctx->block_align;
} }
/** /**
......
...@@ -258,12 +258,6 @@ static int twinvq_read_bitstream(AVCodecContext *avctx, TwinVQContext *tctx, ...@@ -258,12 +258,6 @@ static int twinvq_read_bitstream(AVCodecContext *avctx, TwinVQContext *tctx,
GetBitContext gb; GetBitContext gb;
int i, j, k; int i, j, k;
if (buf_size * 8 < avctx->bit_rate * mtab->size / avctx->sample_rate + 8) {
av_log(avctx, AV_LOG_ERROR,
"Frame too small (%d bytes). Truncated file?\n", buf_size);
return AVERROR(EINVAL);
}
init_get_bits(&gb, buf, buf_size * 8); init_get_bits(&gb, buf, buf_size * 8);
skip_bits(&gb, get_bits(&gb, 8)); skip_bits(&gb, get_bits(&gb, 8));
...@@ -403,6 +397,9 @@ static av_cold int twinvq_decode_init(AVCodecContext *avctx) ...@@ -403,6 +397,9 @@ static av_cold int twinvq_decode_init(AVCodecContext *avctx)
return -1; return -1;
} }
avctx->block_align = (avctx->bit_rate * tctx->mtab->size
/ avctx->sample_rate + 15) / 8;
tctx->codec = TWINVQ_CODEC_VQF; tctx->codec = TWINVQ_CODEC_VQF;
tctx->read_bitstream = twinvq_read_bitstream; tctx->read_bitstream = twinvq_read_bitstream;
tctx->dec_bark_env = dec_bark_env; tctx->dec_bark_env = dec_bark_env;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment