avcodec/avcodec: Check for more invalid channel layouts

In particular, check the provided channel layout for encoders
without AVCodec.ch_layouts set. This fixes an infinite loop
in the WavPack encoder (and maybe other issues in other encoders
as well) in case the channel count is zero.

Reviewed-by: James Almer <jamrial@gmail.com>
Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com>
This commit is contained in:
Andreas Rheinhardt 2022-09-16 02:27:25 +02:00
parent 859d9d70f9
commit a06a2d8943
3 changed files with 14 additions and 10 deletions

View file

@ -602,11 +602,6 @@ static int encode_preinit_audio(AVCodecContext *avctx)
return AVERROR(EINVAL);
}
if (avctx->codec->ch_layouts) {
if (!av_channel_layout_check(&avctx->ch_layout)) {
av_log(avctx, AV_LOG_WARNING, "Channel layout not specified correctly\n");
return AVERROR(EINVAL);
}
for (i = 0; avctx->codec->ch_layouts[i].nb_channels; i++) {
if (!av_channel_layout_compare(&avctx->ch_layout, &avctx->codec->ch_layouts[i]))
break;