summaryrefslogtreecommitdiff
path: root/libavcodec/libopusdec.c
diff options
context:
space:
mode:
authorAndreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>2016-11-14 21:41:45 +0100
committerAndreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>2016-11-25 00:36:36 +0100
commit8c8f543b81aa2b50bb6a6cfd370a0061281492a3 (patch)
tree2ecfeea706ce4d4298079d792e2fb3f5ae1f2718 /libavcodec/libopusdec.c
parent98b3a7979f2ff64cacfba4d8925faa28fc657c51 (diff)
libopusdec: default to stereo for invalid number of channels
This fixes an out-of-bounds read if avc->channels is 0. Reviewed-by: Michael Niedermayer <michael@niedermayer.cc> Signed-off-by: Andreas Cadhalpun <Andreas.Cadhalpun@googlemail.com>
Diffstat (limited to 'libavcodec/libopusdec.c')
-rw-r--r--libavcodec/libopusdec.c7
1 files changed, 7 insertions, 0 deletions
diff --git a/libavcodec/libopusdec.c b/libavcodec/libopusdec.c
index acc62f14d8..e6ca61a78f 100644
--- a/libavcodec/libopusdec.c
+++ b/libavcodec/libopusdec.c
@@ -47,6 +47,13 @@ static av_cold int libopus_decode_init(AVCodecContext *avc)
int ret, channel_map = 0, gain_db = 0, nb_streams, nb_coupled;
uint8_t mapping_arr[8] = { 0, 1 }, *mapping;
+ avc->channels = avc->extradata_size >= 10 ? avc->extradata[9] : (avc->channels == 1) ? 1 : 2;
+ if (avc->channels <= 0) {
+ av_log(avc, AV_LOG_WARNING,
+ "Invalid number of channels %d, defaulting to stereo\n", avc->channels);
+ avc->channels = 2;
+ }
+
avc->sample_rate = 48000;
avc->sample_fmt = avc->request_sample_fmt == AV_SAMPLE_FMT_FLT ?
AV_SAMPLE_FMT_FLT : AV_SAMPLE_FMT_S16;