From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 34F5B443D8 for ; Thu, 8 Sep 2022 23:00:52 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0CE2268BA9B; Fri, 9 Sep 2022 02:00:49 +0300 (EEST) Received: from mail-ot1-f51.google.com (mail-ot1-f51.google.com [209.85.210.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 413B268B6D6 for ; Fri, 9 Sep 2022 02:00:42 +0300 (EEST) Received: by mail-ot1-f51.google.com with SMTP id c39-20020a05683034a700b006540d515722so36837otu.5 for ; Thu, 08 Sep 2022 16:00:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date; bh=wCEWYLtXEAMDHo1/TKtMs0TuBaUTqxSAOMLfVN6/8/s=; b=Ca+M3JkW3iWmzNULwmfzR3c+lFSNgVU5nCpYzMK6ANGMglw0MufAwzETWLYCWwpkr8 Yqmns2nrKIArSmHNjbbWutXg2mIRJyuviDKll6aL7BIQW2ytFy2tRjg7Mld21DZkDOmM ddzMij02ysP5ShKBAIxSdmo6sIKfPvVstvsi26lccdILHaqbbLunft4KNBZdjx40uWtX xqEKsq+NbVLny7aR8+/JroqCTycsSWaSuCsv58rQ5oWdbTntU48UQO+btsWiJsr+EbV5 JJmQhcwTLRPt1HWxA+QEWSAdXqM22h46OAlHpEK5YipDqT/dujbX6h367oYkZqmPUa/t oiDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date; bh=wCEWYLtXEAMDHo1/TKtMs0TuBaUTqxSAOMLfVN6/8/s=; b=0CocMJVlMLOZ1K2nF+ZdPb4adVAmIM6Iz5HGAGYGBqS3dclaWPoqwU2Zltm0A01MzT udikv2jhlsr/sCl4KKq8Yegc9rhXLG/B6nwO4u6PS5ugaZHAH50MJNsZ3xAWbl3dpxpH cmXYFkQs8bYoXJgJ/02wSqkOJdC2jszjPty2ptPAiaWnH7WOCSVbcmcTa3qVsMHKXnRq DUIrnCYZb1qwR5O/9ooBecx72xu4boiMjIOz43GCyFdY41QAlqNQWQ6FQA5Hca+WomRw Q/XP2B/3Hl/P28/rz1MbCJb6+9ntt6EE8KSirgrsVvyhHx/IjN6CXAN5o2CqvzOpd8+t pb9A== X-Gm-Message-State: ACgBeo2uSgXskjb3QodLke4EmwlDtEZ8PLdf/Xwypj3mdrywn9j9Ft5b 84Z/AbA4uOnl5whU2sECIy+GHDsnRJA= X-Google-Smtp-Source: AA6agR5TkAql5NYs6/LPF8occUVZ0Uvs5BIup1Pe4Zmcuc4QpMjT1hBk+Pj3y/oxvQF/UtASn+Dh/Q== X-Received: by 2002:a05:6830:d81:b0:616:abfa:796f with SMTP id bv1-20020a0568300d8100b00616abfa796fmr4282644otb.18.1662678040224; Thu, 08 Sep 2022 16:00:40 -0700 (PDT) Received: from [192.168.0.13] ([191.97.187.183]) by smtp.gmail.com with ESMTPSA id r185-20020aca44c2000000b0034d8f3ed654sm356333oia.1.2022.09.08.16.00.39 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 08 Sep 2022 16:00:39 -0700 (PDT) Message-ID: <370b688d-0a2b-1065-d6c1-18ca54572dff@gmail.com> Date: Thu, 8 Sep 2022 20:00:41 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.13.0 Content-Language: en-US To: ffmpeg-devel@ffmpeg.org References: <20220908224303.3729-1-jamrial@gmail.com> From: James Almer In-Reply-To: Subject: Re: [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 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On 9/8/2022 7:47 PM, Andreas Rheinhardt wrote: > James Almer: >> 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 : ""); > > Why are you using AV_LOG_WARNING when you are erroring out? > >> + 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) || > > It seems that you are not aborting; you are instead erroring out. I'll amend the commit message. > > - Andreas > _______________________________________________ > ffmpeg-devel mailing list > ffmpeg-devel@ffmpeg.org > https://ffmpeg.org/mailman/listinfo/ffmpeg-devel > > To unsubscribe, visit link above, or email > ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe". _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".