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;
}
}
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;
/* 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;
}
}
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++) {
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;
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)
}
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. */
return AVERROR_INVALIDDATA;
}
- cp->sign_huff_offset = calculate_sign_huff(m, substr, ch);
-
return 0;
}
{
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))
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,
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<<ch;
}
for (ch = s->min_channel; ch <= s->max_channel; ch++)
- if (get_bits1(gbp))
+ if (get_bits1(gbp)) {
+ recompute_sho |= 1<<ch;
if ((ret = read_channel_params(m, substr, gbp, ch)) < 0)
- return ret;
+ goto fail;
+ }
- return 0;
+
+fail:
+ for (ch = 0; ch <= s->max_channel; ch++) {
+ if (recompute_sho & (1<<ch)) {
+ ChannelParams *cp = &s->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))
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);
}
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;