Commit 831e749b authored by Michael Niedermayer's avatar Michael Niedermayer

Merge remote-tracking branch 'qatar/master'

* qatar/master:
  aac: return meaningful errors

Conflicts:
	libavcodec/aacdec.c
Merged-by: 's avatarMichael Niedermayer <michaelni@gmx.at>
parents 1bcfb1ee 07c52e2c
...@@ -526,7 +526,7 @@ static int set_default_channel_config(AVCodecContext *avctx, ...@@ -526,7 +526,7 @@ static int set_default_channel_config(AVCodecContext *avctx,
av_log(avctx, AV_LOG_ERROR, av_log(avctx, AV_LOG_ERROR,
"invalid default channel configuration (%d)\n", "invalid default channel configuration (%d)\n",
channel_config); channel_config);
return -1; return AVERROR_INVALIDDATA;
} }
*tags = tags_per_config[channel_config]; *tags = tags_per_config[channel_config];
memcpy(layout_map, aac_channel_layout_map[channel_config - 1], memcpy(layout_map, aac_channel_layout_map[channel_config - 1],
...@@ -726,7 +726,7 @@ static int decode_pce(AVCodecContext *avctx, MPEG4AudioConfig *m4ac, ...@@ -726,7 +726,7 @@ static int decode_pce(AVCodecContext *avctx, MPEG4AudioConfig *m4ac,
comment_len = get_bits(gb, 8) * 8; comment_len = get_bits(gb, 8) * 8;
if (get_bits_left(gb) < comment_len) { if (get_bits_left(gb) < comment_len) {
av_log(avctx, AV_LOG_ERROR, "decode_pce: " overread_err); av_log(avctx, AV_LOG_ERROR, "decode_pce: " overread_err);
return -1; return AVERROR_INVALIDDATA;
} }
skip_bits_long(gb, comment_len); skip_bits_long(gb, comment_len);
return tags; return tags;
...@@ -821,8 +821,7 @@ static int decode_audio_specific_config(AACContext *ac, ...@@ -821,8 +821,7 @@ static int decode_audio_specific_config(AACContext *ac,
int sync_extension) int sync_extension)
{ {
GetBitContext gb; GetBitContext gb;
int i; int i, ret;
int ret;
av_dlog(avctx, "audio specific config size %d\n", bit_size >> 3); av_dlog(avctx, "audio specific config size %d\n", bit_size >> 3);
for (i = 0; i < bit_size >> 3; i++) for (i = 0; i < bit_size >> 3; i++)
...@@ -834,12 +833,12 @@ static int decode_audio_specific_config(AACContext *ac, ...@@ -834,12 +833,12 @@ static int decode_audio_specific_config(AACContext *ac,
if ((i = avpriv_mpeg4audio_get_config(m4ac, data, bit_size, if ((i = avpriv_mpeg4audio_get_config(m4ac, data, bit_size,
sync_extension)) < 0) sync_extension)) < 0)
return -1; return AVERROR_INVALIDDATA;
if (m4ac->sampling_index > 12) { if (m4ac->sampling_index > 12) {
av_log(avctx, AV_LOG_ERROR, av_log(avctx, AV_LOG_ERROR,
"invalid sampling rate index %d\n", "invalid sampling rate index %d\n",
m4ac->sampling_index); m4ac->sampling_index);
return -1; return AVERROR_INVALIDDATA;
} }
skip_bits_long(&gb, i); skip_bits_long(&gb, i);
...@@ -848,15 +847,16 @@ static int decode_audio_specific_config(AACContext *ac, ...@@ -848,15 +847,16 @@ static int decode_audio_specific_config(AACContext *ac,
case AOT_AAC_MAIN: case AOT_AAC_MAIN:
case AOT_AAC_LC: case AOT_AAC_LC:
case AOT_AAC_LTP: case AOT_AAC_LTP:
if (decode_ga_specific_config(ac, avctx, &gb, m4ac, m4ac->chan_config)) if ((ret = decode_ga_specific_config(ac, avctx, &gb,
return -1; m4ac, m4ac->chan_config)) < 0)
return ret;
break; break;
default: default:
av_log(avctx, AV_LOG_ERROR, av_log(avctx, AV_LOG_ERROR,
"Audio object type %s%d is not supported.\n", "Audio object type %s%d is not supported.\n",
m4ac->sbr == 1 ? "SBR+" : "", m4ac->sbr == 1 ? "SBR+" : "",
m4ac->object_type); m4ac->object_type);
return -1; return AVERROR(ENOSYS);
} }
av_dlog(avctx, av_dlog(avctx,
...@@ -934,6 +934,7 @@ static void aacdec_init(AACContext *ac); ...@@ -934,6 +934,7 @@ static void aacdec_init(AACContext *ac);
static av_cold int aac_decode_init(AVCodecContext *avctx) static av_cold int aac_decode_init(AVCodecContext *avctx)
{ {
AACContext *ac = avctx->priv_data; AACContext *ac = avctx->priv_data;
int ret;
ac->avctx = avctx; ac->avctx = avctx;
ac->oc[1].m4ac.sample_rate = avctx->sample_rate; ac->oc[1].m4ac.sample_rate = avctx->sample_rate;
...@@ -943,10 +944,11 @@ static av_cold int aac_decode_init(AVCodecContext *avctx) ...@@ -943,10 +944,11 @@ static av_cold int aac_decode_init(AVCodecContext *avctx)
avctx->sample_fmt = AV_SAMPLE_FMT_FLTP; avctx->sample_fmt = AV_SAMPLE_FMT_FLTP;
if (avctx->extradata_size > 0) { if (avctx->extradata_size > 0) {
if (decode_audio_specific_config(ac, ac->avctx, &ac->oc[1].m4ac, if ((ret = decode_audio_specific_config(ac, ac->avctx, &ac->oc[1].m4ac,
avctx->extradata, avctx->extradata,
avctx->extradata_size * 8, 1) < 0) avctx->extradata_size * 8,
return -1; 1)) < 0)
return ret;
} else { } else {
int sr, i; int sr, i;
uint8_t layout_map[MAX_ELEM_ID*4][3]; uint8_t layout_map[MAX_ELEM_ID*4][3];
...@@ -1041,7 +1043,7 @@ static int skip_data_stream_element(AACContext *ac, GetBitContext *gb) ...@@ -1041,7 +1043,7 @@ static int skip_data_stream_element(AACContext *ac, GetBitContext *gb)
if (get_bits_left(gb) < 8 * count) { if (get_bits_left(gb) < 8 * count) {
av_log(ac->avctx, AV_LOG_ERROR, "skip_data_stream_element: "overread_err); av_log(ac->avctx, AV_LOG_ERROR, "skip_data_stream_element: "overread_err);
return -1; return AVERROR_INVALIDDATA;
} }
skip_bits_long(gb, 8 * count); skip_bits_long(gb, 8 * count);
return 0; return 0;
...@@ -1057,7 +1059,7 @@ static int decode_prediction(AACContext *ac, IndividualChannelStream *ics, ...@@ -1057,7 +1059,7 @@ static int decode_prediction(AACContext *ac, IndividualChannelStream *ics,
ics->predictor_reset_group > 30) { ics->predictor_reset_group > 30) {
av_log(ac->avctx, AV_LOG_ERROR, av_log(ac->avctx, AV_LOG_ERROR,
"Invalid Predictor Reset Group.\n"); "Invalid Predictor Reset Group.\n");
return -1; return AVERROR_INVALIDDATA;
} }
} }
for (sfb = 0; sfb < FFMIN(ics->max_sfb, ff_aac_pred_sfb_max[ac->oc[1].m4ac.sampling_index]); sfb++) { for (sfb = 0; sfb < FFMIN(ics->max_sfb, ff_aac_pred_sfb_max[ac->oc[1].m4ac.sampling_index]); sfb++) {
...@@ -1172,20 +1174,20 @@ static int decode_band_types(AACContext *ac, enum BandType band_type[120], ...@@ -1172,20 +1174,20 @@ static int decode_band_types(AACContext *ac, enum BandType band_type[120],
int sect_band_type = get_bits(gb, 4); int sect_band_type = get_bits(gb, 4);
if (sect_band_type == 12) { if (sect_band_type == 12) {
av_log(ac->avctx, AV_LOG_ERROR, "invalid band type\n"); av_log(ac->avctx, AV_LOG_ERROR, "invalid band type\n");
return -1; return AVERROR_INVALIDDATA;
} }
do { do {
sect_len_incr = get_bits(gb, bits); sect_len_incr = get_bits(gb, bits);
sect_end += sect_len_incr; sect_end += sect_len_incr;
if (get_bits_left(gb) < 0) { if (get_bits_left(gb) < 0) {
av_log(ac->avctx, AV_LOG_ERROR, "decode_band_types: "overread_err); av_log(ac->avctx, AV_LOG_ERROR, "decode_band_types: "overread_err);
return -1; return AVERROR_INVALIDDATA;
} }
if (sect_end > ics->max_sfb) { if (sect_end > ics->max_sfb) {
av_log(ac->avctx, AV_LOG_ERROR, av_log(ac->avctx, AV_LOG_ERROR,
"Number of bands (%d) exceeds limit (%d).\n", "Number of bands (%d) exceeds limit (%d).\n",
sect_end, ics->max_sfb); sect_end, ics->max_sfb);
return -1; return AVERROR_INVALIDDATA;
} }
} while (sect_len_incr == (1 << bits) - 1); } while (sect_len_incr == (1 << bits) - 1);
for (; k < sect_end; k++) { for (; k < sect_end; k++) {
...@@ -1257,7 +1259,7 @@ static int decode_scalefactors(AACContext *ac, float sf[120], GetBitContext *gb, ...@@ -1257,7 +1259,7 @@ static int decode_scalefactors(AACContext *ac, float sf[120], GetBitContext *gb,
if (offset[0] > 255U) { if (offset[0] > 255U) {
av_log(ac->avctx, AV_LOG_ERROR, av_log(ac->avctx, AV_LOG_ERROR,
"Scalefactor (%d) out of range.\n", offset[0]); "Scalefactor (%d) out of range.\n", offset[0]);
return -1; return AVERROR_INVALIDDATA;
} }
sf[idx] = -ff_aac_pow2sf_tab[offset[0] - 100 + POW_SF2_ZERO]; sf[idx] = -ff_aac_pow2sf_tab[offset[0] - 100 + POW_SF2_ZERO];
} }
...@@ -1316,7 +1318,7 @@ static int decode_tns(AACContext *ac, TemporalNoiseShaping *tns, ...@@ -1316,7 +1318,7 @@ static int decode_tns(AACContext *ac, TemporalNoiseShaping *tns,
"TNS filter order %d is greater than maximum %d.\n", "TNS filter order %d is greater than maximum %d.\n",
tns->order[w][filt], tns_max_order); tns->order[w][filt], tns_max_order);
tns->order[w][filt] = 0; tns->order[w][filt] = 0;
return -1; return AVERROR_INVALIDDATA;
} }
if (tns->order[w][filt]) { if (tns->order[w][filt]) {
tns->direction[w][filt] = get_bits1(gb); tns->direction[w][filt] = get_bits1(gb);
...@@ -1602,7 +1604,7 @@ static int decode_spectrum_and_dequant(AACContext *ac, float coef[1024], ...@@ -1602,7 +1604,7 @@ static int decode_spectrum_and_dequant(AACContext *ac, float coef[1024],
if (b > 8) { if (b > 8) {
av_log(ac->avctx, AV_LOG_ERROR, "error in spectral data, ESC overflow\n"); av_log(ac->avctx, AV_LOG_ERROR, "error in spectral data, ESC overflow\n");
return -1; return AVERROR_INVALIDDATA;
} }
SKIP_BITS(re, gb, b + 1); SKIP_BITS(re, gb, b + 1);
...@@ -1751,6 +1753,7 @@ static int decode_ics(AACContext *ac, SingleChannelElement *sce, ...@@ -1751,6 +1753,7 @@ static int decode_ics(AACContext *ac, SingleChannelElement *sce,
IndividualChannelStream *ics = &sce->ics; IndividualChannelStream *ics = &sce->ics;
float *out = sce->coeffs; float *out = sce->coeffs;
int global_gain, pulse_present = 0; int global_gain, pulse_present = 0;
int ret;
/* This assignment is to silence a GCC warning about the variable being used /* This assignment is to silence a GCC warning about the variable being used
* uninitialized when in fact it always is. * uninitialized when in fact it always is.
...@@ -1764,12 +1767,12 @@ static int decode_ics(AACContext *ac, SingleChannelElement *sce, ...@@ -1764,12 +1767,12 @@ static int decode_ics(AACContext *ac, SingleChannelElement *sce,
return AVERROR_INVALIDDATA; return AVERROR_INVALIDDATA;
} }
if (decode_band_types(ac, sce->band_type, if ((ret = decode_band_types(ac, sce->band_type,
sce->band_type_run_end, gb, ics) < 0) sce->band_type_run_end, gb, ics)) < 0)
return -1; return ret;
if (decode_scalefactors(ac, sce->sf, gb, global_gain, ics, if ((ret = decode_scalefactors(ac, sce->sf, gb, global_gain, ics,
sce->band_type, sce->band_type_run_end) < 0) sce->band_type, sce->band_type_run_end)) < 0)
return -1; return ret;
pulse_present = 0; pulse_present = 0;
if (!scale_flag) { if (!scale_flag) {
...@@ -1777,16 +1780,16 @@ static int decode_ics(AACContext *ac, SingleChannelElement *sce, ...@@ -1777,16 +1780,16 @@ static int decode_ics(AACContext *ac, SingleChannelElement *sce,
if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) { if (ics->window_sequence[0] == EIGHT_SHORT_SEQUENCE) {
av_log(ac->avctx, AV_LOG_ERROR, av_log(ac->avctx, AV_LOG_ERROR,
"Pulse tool not allowed in eight short sequence.\n"); "Pulse tool not allowed in eight short sequence.\n");
return -1; return AVERROR_INVALIDDATA;
} }
if (decode_pulses(&pulse, gb, ics->swb_offset, ics->num_swb)) { if (decode_pulses(&pulse, gb, ics->swb_offset, ics->num_swb)) {
av_log(ac->avctx, AV_LOG_ERROR, av_log(ac->avctx, AV_LOG_ERROR,
"Pulse data corrupt or invalid.\n"); "Pulse data corrupt or invalid.\n");
return -1; return AVERROR_INVALIDDATA;
} }
} }
if ((tns->present = get_bits1(gb)) && decode_tns(ac, tns, gb, ics)) if ((tns->present = get_bits1(gb)) && decode_tns(ac, tns, gb, ics))
return -1; return AVERROR_INVALIDDATA;
if (get_bits1(gb)) { if (get_bits1(gb)) {
avpriv_request_sample(ac->avctx, "SSR"); avpriv_request_sample(ac->avctx, "SSR");
return AVERROR_PATCHWELCOME; return AVERROR_PATCHWELCOME;
...@@ -1795,7 +1798,7 @@ static int decode_ics(AACContext *ac, SingleChannelElement *sce, ...@@ -1795,7 +1798,7 @@ static int decode_ics(AACContext *ac, SingleChannelElement *sce,
if (decode_spectrum_and_dequant(ac, out, gb, sce->sf, pulse_present, if (decode_spectrum_and_dequant(ac, out, gb, sce->sf, pulse_present,
&pulse, ics, sce->band_type) < 0) &pulse, ics, sce->band_type) < 0)
return -1; return AVERROR_INVALIDDATA;
if (ac->oc[1].m4ac.object_type == AOT_AAC_MAIN && !common_window) if (ac->oc[1].m4ac.object_type == AOT_AAC_MAIN && !common_window)
apply_prediction(ac, sce); apply_prediction(ac, sce);
...@@ -1897,7 +1900,7 @@ static int decode_cpe(AACContext *ac, GetBitContext *gb, ChannelElement *cpe) ...@@ -1897,7 +1900,7 @@ static int decode_cpe(AACContext *ac, GetBitContext *gb, ChannelElement *cpe)
ms_present = get_bits(gb, 2); ms_present = get_bits(gb, 2);
if (ms_present == 3) { if (ms_present == 3) {
av_log(ac->avctx, AV_LOG_ERROR, "ms_present = 3 is reserved.\n"); av_log(ac->avctx, AV_LOG_ERROR, "ms_present = 3 is reserved.\n");
return -1; return AVERROR_INVALIDDATA;
} else if (ms_present) } else if (ms_present)
decode_mid_side_stereo(cpe, gb, ms_present); decode_mid_side_stereo(cpe, gb, ms_present);
} }
......
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