From patchwork Sat Jul 15 10:45:31 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 42699 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6da1:b0:131:a7d0:bc6d with SMTP id gl33csp4239460pzb; Sat, 15 Jul 2023 03:47:55 -0700 (PDT) X-Google-Smtp-Source: APBJJlGuMP+eF6sEit5shjgBzFh8EkKwlaXvXeZOa10lf403mW0BTAdjif/ni3QaWl0R4I/t3gkO X-Received: by 2002:a5d:670e:0:b0:314:12c:4322 with SMTP id o14-20020a5d670e000000b00314012c4322mr6737284wru.4.1689418075007; Sat, 15 Jul 2023 03:47:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1689418074; cv=none; d=google.com; s=arc-20160816; b=xXUnTSN2rqITrOzjHTX44YgCIUT2aRcWquQrdw+HOFe2oaNup9MMmjd5r9RcrVWdfF rtWnf12Nf9YAxX/tQleVD/ozX2MuSEi7IIU2t0DUMTN+xR4boFbHQy6nF/FFLrIIyRYF 2A4GfkfDdTs0R8Rm5ZjfEHEm6EhRT24d5JKiJa5bTIruU6o9zYvGQb/pKdZ5J+q2w7pl vVCtK1kiSaVo+e5tbHewURcGCZIzT79FCM1sCnwBLvKCIfXfUBatMY4HnyrHwjZxoyh9 1E5t8OmeEOEV2cuGBB7D5XWomW5ZpGeLLsg/uGLwktRJlJ1ku+Aa+t+ik6jfxLnzAhKp OM2Q== 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:references:in-reply-to:message-id :date:to:from:delivered-to; bh=vIU3beMfFqF1RpY/zl2fnQgfxmvB3nRQ44w2z98SZSQ=; fh=8ZF2QtiKOjBtyn9wuO2cMeZaLsE4aq02Bq77gGK61E8=; b=ydKJZOJwPQhxfXpQf8+701yajbd/1nyRxgPDiaQxjSAk8ElyrZYqWNmBmokBQ35Lfp YckTDIYS7hdgRrHEG4K40Yz7o/lDjyxCB27w+SpCtSatr6V5DcRZYu/zRJ3uNnwyv7gt iF4vCdp+tVcPNCJ/nIeSFIzcRcYNUyL5nK5TooCVC7E2ZFioJaPgmU4MGjT/fHoyRDfo HFekxFYMTGnd8Z+GggwvUe3+YdVzJcEW3SrKAwZrZ6LGor8fMUxXipuuVdfixuEvoMKa OhAFT6Igb83xmfffok6R+GHlOZ2uDk5UEjkB+L4YB/ZhfFsxldrD8E70Q2wlISjDH4eX 4yHQ== 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 n23-20020a056402515700b0051debd3e95asi10048953edd.146.2023.07.15.03.47.54; Sat, 15 Jul 2023 03:47:54 -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; 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 C327B68C6B5; Sat, 15 Jul 2023 13:46:43 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BCFB068C64E for ; Sat, 15 Jul 2023 13:46:32 +0300 (EEST) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id ACBD7240591 for ; Sat, 15 Jul 2023 12:46:30 +0200 (CEST) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id xa0I87MvHvCk for ; Sat, 15 Jul 2023 12:46:30 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id A6C9E2405EC for ; Sat, 15 Jul 2023 12:46:26 +0200 (CEST) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id 4362C3A12C9 for ; Sat, 15 Jul 2023 12:46:20 +0200 (CEST) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Jul 2023 12:45:31 +0200 Message-Id: <20230715104611.17902-7-anton@khirnov.net> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230715104611.17902-1-anton@khirnov.net> References: <20230715104611.17902-1-anton@khirnov.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 07/47] fftools/ffmpeg_mux_init: avoid invalid memory access in set_dispositions() 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: IGarmJI06I5q This function assumes AVMEDIA_* are always positive, while in fact it can also handle AVMEDIA_TYPE_UNKNOWN, which is -1. --- fftools/ffmpeg_mux_init.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/fftools/ffmpeg_mux_init.c b/fftools/ffmpeg_mux_init.c index 03d60f2a19..cc5ec68040 100644 --- a/fftools/ffmpeg_mux_init.c +++ b/fftools/ffmpeg_mux_init.c @@ -2296,8 +2296,9 @@ static int set_dispositions(Muxer *mux, const OptionsContext *o) OutputFile *of = &mux->of; AVFormatContext *ctx = mux->fc; - int nb_streams[AVMEDIA_TYPE_NB] = { 0 }; - int have_default[AVMEDIA_TYPE_NB] = { 0 }; + // indexed by type+1, because AVMEDIA_TYPE_UNKNOWN=-1 + int nb_streams[AVMEDIA_TYPE_NB + 1] = { 0 }; + int have_default[AVMEDIA_TYPE_NB + 1] = { 0 }; int have_manual = 0; int ret = 0; @@ -2311,7 +2312,7 @@ static int set_dispositions(Muxer *mux, const OptionsContext *o) for (int i = 0; i < ctx->nb_streams; i++) { OutputStream *ost = of->streams[i]; - nb_streams[ost->type]++; + nb_streams[ost->type + 1]++; MATCH_PER_STREAM_OPT(disposition, str, dispositions[i], ctx, ost->st); @@ -2321,7 +2322,7 @@ static int set_dispositions(Muxer *mux, const OptionsContext *o) ost->st->disposition = ost->ist->st->disposition; if (ost->st->disposition & AV_DISPOSITION_DEFAULT) - have_default[ost->type] = 1; + have_default[ost->type + 1] = 1; } } @@ -2346,12 +2347,12 @@ static int set_dispositions(Muxer *mux, const OptionsContext *o) OutputStream *ost = of->streams[i]; enum AVMediaType type = ost->type; - if (nb_streams[type] < 2 || have_default[type] || + if (nb_streams[type + 1] < 2 || have_default[type + 1] || ost->st->disposition & AV_DISPOSITION_ATTACHED_PIC) continue; ost->st->disposition |= AV_DISPOSITION_DEFAULT; - have_default[type] = 1; + have_default[type + 1] = 1; } }