diff mbox series

[FFmpeg-devel,2/2] avcodec/utils: Require a non zero channels unless AV_CODEC_CAP_CHANNEL_CONF is set

Message ID 20200910120220.6978-2-michael@niedermayer.cc
State New
Headers show
Series [FFmpeg-devel,1/2] avcodec: Set AV_CODEC_CAP_CHANNEL_CONF in more decoders
Related show

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Michael Niedermayer Sept. 10, 2020, 12:02 p.m. UTC
This avoids per codec checks for channels not being 0

Fixes: division by 0
Fixes: 25419/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_FASTAUDIO_fuzzer-5632544761184256
Fixes: 25433/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_FASTAUDIO_fuzzer-6215671900536832

Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
Suggested-by: Paul B Mahol <onemda@gmail.com>
See: [FFmpeg-devel] [PATCH 1/3] avcodec/fastaudio: Check channel
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavcodec/utils.c | 9 +++++++++
 1 file changed, 9 insertions(+)

Comments

Paul B Mahol Sept. 11, 2020, 1:42 p.m. UTC | #1
On Thu, Sep 10, 2020 at 02:02:20PM +0200, Michael Niedermayer wrote:
> This avoids per codec checks for channels not being 0
> 
> Fixes: division by 0
> Fixes: 25419/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_FASTAUDIO_fuzzer-5632544761184256
> Fixes: 25433/clusterfuzz-testcase-minimized-ffmpeg_AV_CODEC_ID_FASTAUDIO_fuzzer-6215671900536832
> 
> Found-by: continuous fuzzing process https://github.com/google/oss-fuzz/tree/master/projects/ffmpeg
> Suggested-by: Paul B Mahol <onemda@gmail.com>
> See: [FFmpeg-devel] [PATCH 1/3] avcodec/fastaudio: Check channel
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavcodec/utils.c | 9 +++++++++
>  1 file changed, 9 insertions(+)

LGTM
diff mbox series

Patch

diff --git a/libavcodec/utils.c b/libavcodec/utils.c
index 2e5185f364..f78ec620c1 100644
--- a/libavcodec/utils.c
+++ b/libavcodec/utils.c
@@ -666,6 +666,15 @@  int attribute_align_arg avcodec_open2(AVCodecContext *avctx, const AVCodec *code
         ret = AVERROR(EINVAL);
         goto free_and_end;
     }
+    if (av_codec_is_decoder(codec) &&
+        codec->type == AVMEDIA_TYPE_AUDIO &&
+        !(codec->capabilities & AV_CODEC_CAP_CHANNEL_CONF) &&
+        avctx->channels == 0) {
+        av_log(avctx, AV_LOG_ERROR, "Decoder requires channel count but channels not set\n");
+        ret = AVERROR(EINVAL);
+        goto free_and_end;
+    }
+
     if (avctx->sample_rate < 0) {
         av_log(avctx, AV_LOG_ERROR, "Invalid sample rate: %d\n", avctx->sample_rate);
         ret = AVERROR(EINVAL);