From patchwork Thu Sep 8 22:43:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 37771 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:139a:b0:8f:1db5:eae2 with SMTP id w26csp571372pzh; Thu, 8 Sep 2022 15:43:41 -0700 (PDT) X-Google-Smtp-Source: AA6agR50Eh4Jk+8EYABw8HQEcCRJHUi86XRB/e0DZo1WXZMKUuhyPEgrvoX+tadCFvQ6DA0ukzrX X-Received: by 2002:a05:6402:254b:b0:448:92fa:3f69 with SMTP id l11-20020a056402254b00b0044892fa3f69mr9030126edb.316.1662677021708; Thu, 08 Sep 2022 15:43:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1662677021; cv=none; d=google.com; s=arc-20160816; b=cO2ZAmlW7+rHqqgw/1STPvNoe5XgLEAWRefDDsLXCt8jw0kyqI/uhU4qzIh9/y00nC d7lYXPq2EHi2bWwohWwnqphV1smOLHBJiKFfmBG7IzuyzT+3NXtqSycw17Cls5fRXGCH Ou2pSfcisMIqTbED6u0OhJA3lO6JyeuzybErBHzWgCSReSPhUd7s7C/qyzQ58eTRlC+G 2sfd+w0lpStG8zmXUC8JDtz5+WHF2kxMhd7zIDR4FsdeXFuRR1NDLr0fLgqopXDbDKjx Y4hkmKSKXc43PsaJqrlxcrjYko3Z05KLCHX+oO6bL7qE/N66xHJws9A0Od9eT5ywpjUL MnYA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:message-id:date:to:from :dkim-signature:delivered-to; bh=wUCs65GqgMu9SWztZnA8EbvR8VtfRuNZzr9jlk/wfNU=; b=zPdTHmGMn46JXfUJDqrqIiVFgNBnmEu34Td3FYh4FyCKCurwBeremxOYAq+cbK5gHD bS4luFwNtFXdGIx8XiXnLQHFKEhIIh+XuFgP1Z5cDCCnVMfN5RfxLGqYZjcHJvkr/O4R GplXc/r+Swrra88f6q8Yy8p3PZcQ/hKBLRkEJbXeYZN2PQKCHD6JrqdBGNWMProek3u9 CjLV258YUwKDcjhvkh8txNSF0MmSNosPX6D+xE9jUzVYEfoFxb6yMO5FiKVupqC5GOAM Ebe1CiUv8DdTOqNl04dLSQKCH3f7Tk3V0vL+/E2H+mp3Nd21pdzlkMoo3y7MeT8NfKsM PKdQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=k1w8YFa3; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id fi15-20020a170906da0f00b00730a11988dcsi70340ejb.562.2022.09.08.15.43.34; Thu, 08 Sep 2022 15:43:41 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=k1w8YFa3; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id A39FF68BAB6; Fri, 9 Sep 2022 01:43:30 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ot1-f42.google.com (mail-ot1-f42.google.com [209.85.210.42]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 34EA468B9F9 for ; Fri, 9 Sep 2022 01:43:24 +0300 (EEST) Received: by mail-ot1-f42.google.com with SMTP id t8-20020a9d5908000000b0063b41908168so8734oth.8 for ; Thu, 08 Sep 2022 15:43:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc:subject:date; bh=bUDgBUObVwGEXaZuWTjDFxIKljWGib6ev1CCxN3LQ8k=; b=k1w8YFa3mx7trXzkfdV54ZcYhriAfm+WhfQMZ401R9aKl4LRG+y7JzAP8oy1RWP/X2 6i1N9NvYA954sqxfR+LaDp75X+75MMmhIGSc5sTA4Jf3A0Sn0g9qS/SjYwZr43JjWYkA hDo0qMHYmiwyybAMY6jiElk4+840BbS3mNgm5Tf4WvF6rFc2ZX08toqDCpjb5asBgNuS F8KWdu0K3SIxN77s1Nc7/y3P/hn1Ogt2kM3fRhPz/XZQslKVq+k8O98B9wQM+77+Juat 9FPn+8+W3RSySE8K5V0dv1hvkQyCxHzISCtNeTg3/9XTusAe+wo8a9+Sb1S6H1ekQCpj Rm2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date; bh=bUDgBUObVwGEXaZuWTjDFxIKljWGib6ev1CCxN3LQ8k=; b=T1xpL+sN/Wh7EyBq1PGhhV22VL8IIMvN4sqNO65qmn9OWkCSqjmYostE2GXrBX3p5l 0NafPx2rffketUGrQiyLZaSeA6z/IwoqoYkbZ/pflyrLRg8oYzb8Ga+0sGrhv0AR02vF 19X20L/laBeNJJ1I0nI83PDaFln4IhkXUu0295Dk1JnOQo2jCvyocpdKzseO6rJrDSh7 eQ74A2XN2J1rIRacF6HhY2RT0tgyJE7qQsQcEN7Fm6Gxi417PtfHGAsB/agcbPn2ww68 Sk5eV/GYVKNKaIf1PtWrRaT3jiulkCcveH1BsTI7fYGBsFl9yaT/NViXZqMFWA3LP1md 44ew== X-Gm-Message-State: ACgBeo01kTgdEAW5NadSp48dafkW1pCZBAPXJZC1cWMQfC9AoXu+FvYu 3dwbPhgSgBo4f1F+zVf+zDl22e/Q5qQ= X-Received: by 2002:a9d:b92:0:b0:654:7da5:9bfb with SMTP id 18-20020a9d0b92000000b006547da59bfbmr412348oth.176.1662677002051; Thu, 08 Sep 2022 15:43:22 -0700 (PDT) Received: from localhost.localdomain ([191.97.187.183]) by smtp.gmail.com with ESMTPSA id z203-20020a4a49d4000000b00448a3ecdc9dsm352790ooa.22.2022.09.08.15.43.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 08 Sep 2022 15:43:21 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Thu, 8 Sep 2022 19:43:03 -0300 Message-Id: <20220908224303.3729-1-jamrial@gmail.com> X-Mailer: git-send-email 2.37.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] swsresample/swresample: abort on invalid layouts X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: iMXJKVeEELQ8 If it's unsupported or invalid, then there's no point trying to rebuild it using a value that may have been derived from the same layout to begin with. Move the checks before the attempts at copying the layout while at it. Fixes ticket #9908. Signed-off-by: James Almer --- libswresample/swresample.c | 48 +++++++++++++++++++++++++------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/libswresample/swresample.c b/libswresample/swresample.c index 6f04d130d3..5884f8d533 100644 --- a/libswresample/swresample.c +++ b/libswresample/swresample.c @@ -227,7 +227,7 @@ av_cold int swr_init(struct SwrContext *s){ s->in_ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; s->in_ch_layout.nb_channels = s->user_in_ch_count; } - } else + } else if (av_channel_layout_check(&s->user_in_chlayout)) av_channel_layout_copy(&s->in_ch_layout, &s->user_in_chlayout); if ((s->user_out_ch_count && s->user_out_ch_count != s->user_out_chlayout.nb_channels) || @@ -240,17 +240,45 @@ av_cold int swr_init(struct SwrContext *s){ s->out_ch_layout.order = AV_CHANNEL_ORDER_UNSPEC; s->out_ch_layout.nb_channels = s->user_out_ch_count; } - } else + } else if (av_channel_layout_check(&s->user_out_chlayout)) av_channel_layout_copy(&s->out_ch_layout, &s->user_out_chlayout); if (!s->out.ch_count && !s->user_out_ch_layout) s->out.ch_count = s->out_ch_layout.nb_channels; if (!s-> in.ch_count && !s-> user_in_ch_layout) s-> in.ch_count = s->in_ch_layout.nb_channels; + + if (!(ret = av_channel_layout_check(&s->in_ch_layout)) || s->in_ch_layout.nb_channels > SWR_CH_MAX) { + if (ret) + av_channel_layout_describe(&s->in_ch_layout, l1, sizeof(l1)); + av_log(s, AV_LOG_WARNING, "Input channel layout \"%s\" is invalid or unsupported.\n", ret ? l1 : ""); + return AVERROR(EINVAL); + } + + if (!(ret = av_channel_layout_check(&s->out_ch_layout)) || s->out_ch_layout.nb_channels > SWR_CH_MAX) { + if (ret) + av_channel_layout_describe(&s->out_ch_layout, l2, sizeof(l2)); + av_log(s, AV_LOG_WARNING, "Output channel layout \"%s\" is invalid or unsupported.\n", ret ? l2 : ""); + return AVERROR(EINVAL); + } #else s->out.ch_count = s-> user_out_chlayout.nb_channels; s-> in.ch_count = s-> user_in_chlayout.nb_channels; + if (!(ret = av_channel_layout_check(&s->user_in_chlayout)) || s->user_in_chlayout.nb_channels > SWR_CH_MAX) { + if (ret) + av_channel_layout_describe(&s->user_in_chlayout, l1, sizeof(l1)); + av_log(s, AV_LOG_WARNING, "Input channel layout \"%s\" is invalid or unsupported.\n", ret ? l1 : ""); + return AVERROR(EINVAL); + } + + if (!(ret = av_channel_layout_check(&s->user_out_chlayout)) || s->user_out_chlayout.nb_channels > SWR_CH_MAX) { + if (ret) + av_channel_layout_describe(&s->user_out_chlayout, l2, sizeof(l2)); + av_log(s, AV_LOG_WARNING, "Output channel layout \"%s\" is invalid or unsupported.\n", ret ? l2 : ""); + return AVERROR(EINVAL); + } + ret = av_channel_layout_copy(&s->in_ch_layout, &s->user_in_chlayout); ret |= av_channel_layout_copy(&s->out_ch_layout, &s->user_out_chlayout); if (ret < 0) @@ -261,18 +289,6 @@ av_cold int swr_init(struct SwrContext *s){ s->dither.method = s->user_dither_method; - if (!av_channel_layout_check(&s->in_ch_layout) || s->in_ch_layout.nb_channels > SWR_CH_MAX) { - av_channel_layout_describe(&s->in_ch_layout, l1, sizeof(l1)); - av_log(s, AV_LOG_WARNING, "Input channel layout \"%s\" is invalid or unsupported.\n", l1); - av_channel_layout_uninit(&s->in_ch_layout); - } - - if (!av_channel_layout_check(&s->out_ch_layout) || s->out_ch_layout.nb_channels > SWR_CH_MAX) { - av_channel_layout_describe(&s->out_ch_layout, l2, sizeof(l2)); - av_log(s, AV_LOG_WARNING, "Output channel layout \"%s\" is invalid or unsupported.\n", l2); - av_channel_layout_uninit(&s->out_ch_layout); - } - switch(s->engine){ #if CONFIG_LIBSOXR case SWR_ENGINE_SOXR: s->resampler = &swri_soxr_resampler; break; @@ -291,9 +307,9 @@ av_cold int swr_init(struct SwrContext *s){ av_channel_layout_uninit(&s->in_ch_layout); } - if (!s->in_ch_layout.nb_channels || s->in_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) + if (s->in_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) av_channel_layout_default(&s->in_ch_layout, s->used_ch_count); - if (!s->out_ch_layout.nb_channels || s->out_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) + if (s->out_ch_layout.order == AV_CHANNEL_ORDER_UNSPEC) av_channel_layout_default(&s->out_ch_layout, s->out.ch_count); s->rematrix = av_channel_layout_compare(&s->out_ch_layout, &s->in_ch_layout) ||