X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavcodec%2Fmlpdec.c;h=d5585d308079bc197ac8e1aaf9594c166c8b6f33;hb=49ae8a5e87f99b15514f5ef075d801e9ea8374e9;hp=c93b058dd7a66f4eb39299f6fd17b5ea65383640;hpb=06aafda03f1c097c9ff0c669eb456e86043451e2;p=ffmpeg diff --git a/libavcodec/mlpdec.c b/libavcodec/mlpdec.c index c93b058dd7a..d5585d30807 100644 --- a/libavcodec/mlpdec.c +++ b/libavcodec/mlpdec.c @@ -264,7 +264,7 @@ static inline int read_huff_channels(MLPDecodeContext *m, GetBitContext *gbp, result = (result << lsb_bits) + get_bits(gbp, lsb_bits); result += cp->sign_huff_offset; - result <<= quant_step_size; + result *= 1 << quant_step_size; m->sample_buffer[pos + s->blockpos][channel] = result; } @@ -684,7 +684,7 @@ static int read_filter_params(MLPDecodeContext *m, GetBitContext *gbp, } for (i = 0; i < order; i++) - fcoeff[i] = get_sbits(gbp, coeff_bits) << coeff_shift; + fcoeff[i] = get_sbits(gbp, coeff_bits) * (1 << coeff_shift); if (get_bits1(gbp)) { int state_bits, state_shift; @@ -701,7 +701,7 @@ static int read_filter_params(MLPDecodeContext *m, GetBitContext *gbp, /* TODO: Check validity of state data. */ for (i = 0; i < order; i++) - fp->state[i] = state_bits ? get_sbits(gbp, state_bits) << state_shift : 0; + fp->state[i] = state_bits ? get_sbits(gbp, state_bits) * (1 << state_shift) : 0; } } @@ -729,7 +729,7 @@ static int read_matrix_params(MLPDecodeContext *m, unsigned int substr, GetBitCo av_log(m->avctx, AV_LOG_ERROR, "Number of primitive matrices cannot be greater than %d.\n", max_primitive_matrices); - return AVERROR_INVALIDDATA; + goto error; } for (mat = 0; mat < s->num_primitive_matrices; mat++) { @@ -742,12 +742,12 @@ static int read_matrix_params(MLPDecodeContext *m, unsigned int substr, GetBitCo av_log(m->avctx, AV_LOG_ERROR, "Invalid channel %d specified as output from matrix.\n", s->matrix_out_ch[mat]); - return AVERROR_INVALIDDATA; + goto error; } if (frac_bits > 14) { av_log(m->avctx, AV_LOG_ERROR, "Too many fractional bits specified.\n"); - return AVERROR_INVALIDDATA; + goto error; } max_chan = s->max_matrix_channel; @@ -759,7 +759,7 @@ static int read_matrix_params(MLPDecodeContext *m, unsigned int substr, GetBitCo if (get_bits1(gbp)) coeff_val = get_sbits(gbp, frac_bits + 2); - s->matrix_coeff[mat][ch] = coeff_val << (14 - frac_bits); + s->matrix_coeff[mat][ch] = coeff_val * (1 << (14 - frac_bits)); } if (s->noise_type) @@ -769,6 +769,11 @@ static int read_matrix_params(MLPDecodeContext *m, unsigned int substr, GetBitCo } return 0; +error: + s->num_primitive_matrices = 0; + memset(s->matrix_out_ch, 0, sizeof(s->matrix_out_ch)); + + return AVERROR_INVALIDDATA; } /** Read channel parameters. */ @@ -824,8 +829,6 @@ static int read_channel_params(MLPDecodeContext *m, unsigned int substr, return AVERROR_INVALIDDATA; } - cp->sign_huff_offset = calculate_sign_huff(m, substr, ch); - return 0; } @@ -837,7 +840,8 @@ static int read_decoding_params(MLPDecodeContext *m, GetBitContext *gbp, { SubStream *s = &m->substream[substr]; unsigned int ch; - int ret; + int ret = 0; + unsigned recompute_sho = 0; if (s->param_presence_flags & PARAM_PRESENCE) if (get_bits1(gbp)) @@ -860,8 +864,13 @@ static int read_decoding_params(MLPDecodeContext *m, GetBitContext *gbp, if (s->param_presence_flags & PARAM_OUTSHIFT) if (get_bits1(gbp)) { - for (ch = 0; ch <= s->max_matrix_channel; ch++) + for (ch = 0; ch <= s->max_matrix_channel; ch++) { s->output_shift[ch] = get_sbits(gbp, 4); + if (s->output_shift[ch] < 0) { + avpriv_request_sample(m->avctx, "Negative output_shift"); + s->output_shift[ch] = 0; + } + } if (substr == m->max_decoded_substream) m->dsp.mlp_pack_output = m->dsp.mlp_select_pack_output(s->ch_assign, s->output_shift, @@ -872,19 +881,36 @@ static int read_decoding_params(MLPDecodeContext *m, GetBitContext *gbp, if (s->param_presence_flags & PARAM_QUANTSTEP) if (get_bits1(gbp)) for (ch = 0; ch <= s->max_channel; ch++) { - ChannelParams *cp = &s->channel_params[ch]; - s->quant_step_size[ch] = get_bits(gbp, 4); - cp->sign_huff_offset = calculate_sign_huff(m, substr, ch); + recompute_sho |= 1<min_channel; ch <= s->max_channel; ch++) - if (get_bits1(gbp)) + if (get_bits1(gbp)) { + recompute_sho |= 1<max_channel; ch++) { + if (recompute_sho & (1<channel_params[ch]; + + if (cp->codebook > 0 && cp->huff_lsbs < s->quant_step_size[ch]) { + if (ret >= 0) { + av_log(m->avctx, AV_LOG_ERROR, "quant_step_size larger than huff_lsbs\n"); + ret = AVERROR_INVALIDDATA; + } + s->quant_step_size[ch] = 0; + } + + cp->sign_huff_offset = calculate_sign_huff(m, substr, ch); + } + } + return ret; } #define MSB_MASK(bits) (-1u << (bits)) @@ -999,8 +1025,8 @@ static void generate_2_noise_channels(MLPDecodeContext *m, unsigned int substr) for (i = 0; i < s->blockpos; i++) { uint16_t seed_shr7 = seed >> 7; - m->sample_buffer[i][maxchan+1] = ((int8_t)(seed >> 15)) << s->noise_shift; - m->sample_buffer[i][maxchan+2] = ((int8_t) seed_shr7) << s->noise_shift; + m->sample_buffer[i][maxchan+1] = ((int8_t)(seed >> 15)) * (1 << s->noise_shift); + m->sample_buffer[i][maxchan+2] = ((int8_t) seed_shr7) * (1 << s->noise_shift); seed = (seed << 16) ^ seed_shr7 ^ (seed_shr7 << 5); } @@ -1162,6 +1188,11 @@ static int read_access_unit(AVCodecContext *avctx, void* data, substr_header_size += 2; } + if (length < header_size + substr_header_size) { + av_log(m->avctx, AV_LOG_ERROR, "Insuffient data for headers\n"); + goto error; + } + if (!(nonrestart_substr ^ m->is_major_sync_unit)) { av_log(m->avctx, AV_LOG_ERROR, "Invalid nonrestart_substr.\n"); goto error;