From 9853e41aa0a6cfff629ff7009685eb8bf8d64e7f Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Sat, 24 Mar 2012 01:39:13 +0100 Subject: alsdec: check opt_order. Fixes out of array write in quant_cof. Also make sure no invalid opt_order stays in the context. Fixes CVE-2012-2775 Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind Signed-off-by: Michael Niedermayer Signed-off-by: Justin Ruggles --- libavcodec/alsdec.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'libavcodec/alsdec.c') diff --git a/libavcodec/alsdec.c b/libavcodec/alsdec.c index ef12253271..defe3c4850 100644 --- a/libavcodec/alsdec.c +++ b/libavcodec/alsdec.c @@ -668,6 +668,11 @@ static int read_var_block_data(ALSDecContext *ctx, ALSBlockData *bd) int opt_order_length = av_ceil_log2(av_clip((bd->block_length >> 3) - 1, 2, sconf->max_order + 1)); *bd->opt_order = get_bits(gb, opt_order_length); + if (*bd->opt_order > sconf->max_order) { + *bd->opt_order = sconf->max_order; + av_log(avctx, AV_LOG_ERROR, "Predictor order too large!\n"); + return AVERROR_INVALIDDATA; + } } else { *bd->opt_order = sconf->max_order; } -- cgit v1.2.1 From 5b051ec3bdc78f3d89e8d1425674cde8fd6c9ccc Mon Sep 17 00:00:00 2001 From: Michael Niedermayer Date: Wed, 29 Feb 2012 06:10:17 +0100 Subject: alsdec: Check that quantized parcor coeffs are within range. ALS spec: 11.6.3.1.1 Quantization and encoding of parcor coefficients ... In all cases the resulting quantized values ak are restricted to the range [-64,63]. Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind Signed-off-by: Michael Niedermayer Signed-off-by: Justin Ruggles --- libavcodec/alsdec.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'libavcodec/alsdec.c') diff --git a/libavcodec/alsdec.c b/libavcodec/alsdec.c index defe3c4850..b4bc41bee1 100644 --- a/libavcodec/alsdec.c +++ b/libavcodec/alsdec.c @@ -705,6 +705,10 @@ static int read_var_block_data(ALSDecContext *ctx, ALSBlockData *bd) int rice_param = parcor_rice_table[sconf->coef_table][k][1]; int offset = parcor_rice_table[sconf->coef_table][k][0]; quant_cof[k] = decode_rice(gb, rice_param) + offset; + if (quant_cof[k] < -64 || quant_cof[k] > 63) { + av_log(avctx, AV_LOG_ERROR, "quant_cof %d is out of range\n", quant_cof[k]); + return AVERROR_INVALIDDATA; + } } // read coefficients 20 to 126 -- cgit v1.2.1 From 97f0efbfb86d24f081b2caa39f6249e05c95c2ef Mon Sep 17 00:00:00 2001 From: Thilo Borgmann Date: Sun, 11 Mar 2012 16:56:23 +0100 Subject: alsdec: Fix out of ltp_gain_values read. Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind Signed-off-by: Michael Niedermayer Signed-off-by: Justin Ruggles --- libavcodec/alsdec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libavcodec/alsdec.c') diff --git a/libavcodec/alsdec.c b/libavcodec/alsdec.c index b4bc41bee1..3990b502bf 100644 --- a/libavcodec/alsdec.c +++ b/libavcodec/alsdec.c @@ -741,7 +741,7 @@ static int read_var_block_data(ALSDecContext *ctx, ALSBlockData *bd) bd->ltp_gain[0] = decode_rice(gb, 1) << 3; bd->ltp_gain[1] = decode_rice(gb, 2) << 3; - r = get_unary(gb, 0, 4); + r = get_unary(gb, 0, 3); c = get_bits(gb, 2); bd->ltp_gain[2] = ltp_gain_values[r][c]; -- cgit v1.2.1 From 66197988b1ee914825afbc3084e6da63f862068a Mon Sep 17 00:00:00 2001 From: Thilo Borgmann Date: Sun, 15 Apr 2012 18:07:12 +0200 Subject: alsdec: fix number of decoded samples in first sub-block in BGMC mode. Fixes CVE-2012-2790 Found-by: Mateusz "j00ru" Jurczyk and Gynvael Coldwind Signed-off-by: Michael Niedermayer Signed-off-by: Justin Ruggles --- libavcodec/alsdec.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'libavcodec/alsdec.c') diff --git a/libavcodec/alsdec.c b/libavcodec/alsdec.c index 3990b502bf..02307795fb 100644 --- a/libavcodec/alsdec.c +++ b/libavcodec/alsdec.c @@ -770,7 +770,6 @@ static int read_var_block_data(ALSDecContext *ctx, ALSBlockData *bd) int delta[8]; unsigned int k [8]; unsigned int b = av_clip((av_ceil_log2(bd->block_length) - 3) >> 1, 0, 5); - unsigned int i; // read most significant bits unsigned int high; @@ -782,28 +781,29 @@ static int read_var_block_data(ALSDecContext *ctx, ALSBlockData *bd) current_res = bd->raw_samples + start; for (sb = 0; sb < sub_blocks; sb++) { + unsigned int sb_len = sb_length - (sb ? 0 : start); + k [sb] = s[sb] > b ? s[sb] - b : 0; delta[sb] = 5 - s[sb] + k[sb]; - ff_bgmc_decode(gb, sb_length, current_res, + ff_bgmc_decode(gb, sb_len, current_res, delta[sb], sx[sb], &high, &low, &value, ctx->bgmc_lut, ctx->bgmc_lut_status); - current_res += sb_length; + current_res += sb_len; } ff_bgmc_decode_end(gb); // read least significant bits and tails - i = start; current_res = bd->raw_samples + start; - for (sb = 0; sb < sub_blocks; sb++, i = 0) { + for (sb = 0; sb < sub_blocks; sb++, start = 0) { unsigned int cur_tail_code = tail_code[sx[sb]][delta[sb]]; unsigned int cur_k = k[sb]; unsigned int cur_s = s[sb]; - for (; i < sb_length; i++) { + for (; start < sb_length; start++) { int32_t res = *current_res; if (res == cur_tail_code) { -- cgit v1.2.1 From ac3f5a6879396680c616eabba13609c753939070 Mon Sep 17 00:00:00 2001 From: Thilo Borgmann Date: Tue, 27 Mar 2012 18:06:54 +0200 Subject: alsdec: check return values. Signed-off-by: Justin Ruggles --- libavcodec/alsdec.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) (limited to 'libavcodec/alsdec.c') diff --git a/libavcodec/alsdec.c b/libavcodec/alsdec.c index 02307795fb..dce76b0a71 100644 --- a/libavcodec/alsdec.c +++ b/libavcodec/alsdec.c @@ -1348,7 +1348,7 @@ static int read_frame_data(ALSDecContext *ctx, unsigned int ra_frame) } } else { // multi-channel coding ALSBlockData bd = { 0 }; - int b; + int b, ret; int *reverted_channels = ctx->reverted_channels; unsigned int offset = 0; @@ -1381,9 +1381,10 @@ static int read_frame_data(ALSDecContext *ctx, unsigned int ra_frame) bd.raw_samples = ctx->raw_samples[c] + offset; bd.raw_other = NULL; - read_block(ctx, &bd); - if (read_channel_data(ctx, ctx->chan_data[c], c)) - return -1; + if ((ret = read_block(ctx, &bd)) < 0) + return ret; + if ((ret = read_channel_data(ctx, ctx->chan_data[c], c)) < 0) + return ret; } for (c = 0; c < avctx->channels; c++) @@ -1402,7 +1403,8 @@ static int read_frame_data(ALSDecContext *ctx, unsigned int ra_frame) bd.lpc_cof = ctx->lpc_cof[c]; bd.quant_cof = ctx->quant_cof[c]; bd.raw_samples = ctx->raw_samples[c] + offset; - decode_block(ctx, &bd); + if ((ret = decode_block(ctx, &bd)) < 0) + return ret; } memset(reverted_channels, 0, avctx->channels * sizeof(*reverted_channels)); -- cgit v1.2.1 From ee0f53e966e3a637d9e0050d7be2689d4631faef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20B=C5=93sch?= Date: Tue, 4 Sep 2012 14:30:14 -0400 Subject: alsdec: fix misplaced parentheses. Signed-off-by: Justin Ruggles --- libavcodec/alsdec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'libavcodec/alsdec.c') diff --git a/libavcodec/alsdec.c b/libavcodec/alsdec.c index dce76b0a71..1c3f0cbdb5 100644 --- a/libavcodec/alsdec.c +++ b/libavcodec/alsdec.c @@ -1453,7 +1453,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame_ptr, ctx->cur_frame_length = sconf->frame_length; // decode the frame data - if ((invalid_frame = read_frame_data(ctx, ra_frame) < 0)) + if ((invalid_frame = read_frame_data(ctx, ra_frame)) < 0) av_log(ctx->avctx, AV_LOG_WARNING, "Reading frame data failed. Skipping RA unit.\n"); -- cgit v1.2.1