aboutsummaryrefslogtreecommitdiffstats
path: root/libavcodec/ac3dec.c
diff options
context:
space:
mode:
authorJustin Ruggles <justin.ruggles@gmail.com>2013-02-20 11:41:20 -0500
committerLuca Barbato <lu_zero@gentoo.org>2013-09-21 15:21:54 +0200
commit763519536b63636006c9a421a4b83a58d353b84e (patch)
tree016fcdb63e938cc18485b1aaec4895cf108c8383 /libavcodec/ac3dec.c
parent521cbcb7d37fa12bf1038d1a73bbabcbf62589ed (diff)
downloadffmpeg-763519536b63636006c9a421a4b83a58d353b84e.tar.gz
ac3dec: validate channel output mode against channel count
Damaged frames can lead to a mismatch, which can cause a segfault due to using an incorrect channel mapping. CC:libav-stable@libav.org (cherry picked from commit d7c450436fcb9d3ecf59884a574e7684183e753d) Conflicts: libavcodec/ac3dec.c
Diffstat (limited to 'libavcodec/ac3dec.c')
-rw-r--r--libavcodec/ac3dec.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/libavcodec/ac3dec.c b/libavcodec/ac3dec.c
index 28a783a075..61097e99d9 100644
--- a/libavcodec/ac3dec.c
+++ b/libavcodec/ac3dec.c
@@ -1373,8 +1373,10 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data,
if (!err) {
avctx->sample_rate = s->sample_rate;
avctx->bit_rate = s->bit_rate;
+ }
- /* channel config */
+ /* channel config */
+ if (!err || (s->channels && s->out_channels != s->channels)) {
s->out_channels = s->channels;
s->output_mode = s->channel_mode;
if (s->lfe_on)
@@ -1393,18 +1395,18 @@ static int ac3_decode_frame(AVCodecContext * avctx, void *data,
s->fbw_channels == s->out_channels)) {
set_downmix_coeffs(s);
}
- } else if (!s->out_channels) {
- s->out_channels = avctx->channels;
- if (s->out_channels < s->channels)
- s->output_mode = s->out_channels == 1 ? AC3_CHMODE_MONO : AC3_CHMODE_STEREO;
+ } else if (!s->channels) {
+ av_log(avctx, AV_LOG_ERROR, "unable to determine channel mode\n");
+ return AVERROR_INVALIDDATA;
}
+ avctx->channels = s->out_channels;
+
/* set audio service type based on bitstream mode for AC-3 */
avctx->audio_service_type = s->bitstream_mode;
if (s->bitstream_mode == 0x7 && s->channels > 1)
avctx->audio_service_type = AV_AUDIO_SERVICE_TYPE_KARAOKE;
/* get output buffer */
- avctx->channels = s->out_channels;
s->frame.nb_samples = s->num_blocks * 256;
if ((ret = avctx->get_buffer(avctx, &s->frame)) < 0) {
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");