From patchwork Sat Mar 9 21:54:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marton Balint X-Patchwork-Id: 46925 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:dc95:b0:1a1:738b:6bc0 with SMTP id ky21csp442338pzb; Sat, 9 Mar 2024 13:55:18 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUVScLPDxC+cckK5VP3SZmWglf/yPcWPK3wi/qzhuXN6RqpCiylVM7xHu/YsWZSMA3JrEmYwpDbBTX2XaK2za2ZcDFITVlN5OlWzQ== X-Google-Smtp-Source: AGHT+IGKsFNmDfeFJAE3F5HAHKSwadE5x+2SGaQ2WJbDPJsFqBYqHjOMIejG8sShcOgfaRQ3UjUc X-Received: by 2002:a17:906:2616:b0:a45:b5a0:f3a with SMTP id h22-20020a170906261600b00a45b5a00f3amr1342147ejc.17.1710021318046; Sat, 09 Mar 2024 13:55:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1710021318; cv=none; d=google.com; s=arc-20160816; b=y05ZuxaO4FQfKzmWRNyqdaPaYDp8VFQYnBdw+pdSEtgF3I5z/O+sto6Yd0DEg5PP4N vFiqPTdl96GDwEVuCniBvRAbFqNs0EXGpZb7n+ixPORj5qQaO24cLkx1mlgoEUMvBP2V 2cDlYW8EAO9DeqJAXKcBj2FAha6r/L6CuKBYSrOtOSd2q2awCaY4hBXjK2h+ev4SLInT n/qtZZSDBK3frG3j9CDeFky4SECY5AzgqdWDfBveamCRfVBaRFx8JuN0euwMd0E4zGQu KYURmdVtrWEXoGJcwyvXqNs3niuVNkRVaWviuVIJWetS1kns4/rSXNR5C4iw1916cFTF w04A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:references:in-reply-to :message-id:date:to:from:delivered-to; bh=E+19Zus0R7cOXT1Wo4YkoPLFho7kcyR8IjcTtHZUr2A=; fh=s+G8Ss4JbeMFkWPSp2LmIH/LXFyBlALRiww1j3FPjHY=; b=IFi+SRS/n2CQIXP7u5jWtEu1UyT7EPLoDr2sWpKAs3eGX1TX9FctLpuhC95Nl7teUG X47Cji7YZBhhWxNxx6qDkCsCP8Ygo6jrhbrfvtb0DtAAssKWoIjh6E1ZscTG/97GIQ24 zy4NC+uMWoe3ojvxnzLOyXwL+tgMtSNVLX2JuEcPfbwiqxkjz4AS+V9OFIZHWoXC6ceX BJNGR54IJ5hO4L2u+TNyjm6/rlZA2iO36fSBKNh66F8Ywt5qL5R5z667SWDzvM56ssp3 ufmfBkusToLFppMyFWF5W171kvA4nquUm8Bx2D/OfshHEEUScuDcGhXMERagfMlrjNOx Ewmw==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id g8-20020a1709063b0800b00a44387ebd42si1015531ejf.886.2024.03.09.13.55.17; Sat, 09 Mar 2024 13:55:18 -0800 (PST) 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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 626B368CEE5; Sat, 9 Mar 2024 23:54:51 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from iq.passwd.hu (iq.passwd.hu [217.27.212.140]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 16CBF68CBCB for ; Sat, 9 Mar 2024 23:54:45 +0200 (EET) Received: from localhost (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id E9910E98EB; Sat, 9 Mar 2024 22:54:44 +0100 (CET) X-Virus-Scanned: amavisd-new at passwd.hu Received: from iq.passwd.hu ([127.0.0.1]) by localhost (iq.passwd.hu [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id x8ce6GkjohEf; Sat, 9 Mar 2024 22:54:43 +0100 (CET) Received: from bluegene.passwd.hu (localhost [127.0.0.1]) by iq.passwd.hu (Postfix) with ESMTP id 67766E9B87; Sat, 9 Mar 2024 22:54:43 +0100 (CET) From: Marton Balint To: ffmpeg-devel@ffmpeg.org Date: Sat, 9 Mar 2024 22:54:13 +0100 Message-Id: <20240309215414.26699-6-cus@passwd.hu> X-Mailer: git-send-email 2.35.3 In-Reply-To: <20240309215414.26699-1-cus@passwd.hu> References: <20240309215414.26699-1-cus@passwd.hu> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 6/7] avutil/channel_layout: fix some (un)initialization issues in av_channel_layout_from_string() 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 Cc: Marton Balint Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: wV0YcAw6ZCOe Also make initialization/uninitialization behaviour more explicit in the docs, and make sure we do not leak a channel map on error. Signed-off-by: Marton Balint --- libavutil/channel_layout.c | 5 +++++ libavutil/channel_layout.h | 8 ++++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/libavutil/channel_layout.c b/libavutil/channel_layout.c index 5db4cc9df0..9e8a1c12e6 100644 --- a/libavutil/channel_layout.c +++ b/libavutil/channel_layout.c @@ -302,6 +302,10 @@ int av_channel_layout_from_string(AVChannelLayout *channel_layout, } } + /* This function is a channel layout initializer, so we have to + * zero-initialize before we start setting fields individually. */ + memset(channel_layout, 0, sizeof(*channel_layout)); + /* ambisonic */ if (!strncmp(str, "ambisonic ", 10)) { const char *p = str + 10; @@ -343,6 +347,7 @@ int av_channel_layout_from_string(AVChannelLayout *channel_layout, for (i = 0; i < extra.nb_channels; i++) { enum AVChannel ch = av_channel_layout_channel_from_index(&extra, i); if (CHAN_IS_AMBI(ch)) { + av_channel_layout_uninit(channel_layout); av_channel_layout_uninit(&extra); return AVERROR(EINVAL); } diff --git a/libavutil/channel_layout.h b/libavutil/channel_layout.h index a1e9b08064..8a078d1601 100644 --- a/libavutil/channel_layout.h +++ b/libavutil/channel_layout.h @@ -512,10 +512,14 @@ int av_channel_layout_from_mask(AVChannelLayout *channel_layout, uint64_t mask); * - the number of unordered channels (eg. "4C" or "4 channels") * - the ambisonic order followed by optional non-diegetic channels (eg. * "ambisonic 2+stereo") + * On error, the channel layout will remain uninitialized, but not necessarily + * untouched. * - * @param channel_layout input channel layout + * @param channel_layout uninitialized channel layout for the result * @param str string describing the channel layout - * @return 0 channel layout was detected, AVERROR_INVALIDATATA otherwise + * @return 0 on success parsing the channel layout + * AVERROR(EINVAL) if an invalid channel layout string was provided + * AVERROR(ENOMEM) if there was not enough memory */ int av_channel_layout_from_string(AVChannelLayout *channel_layout, const char *str);