From patchwork Sat Aug 15 05:48:10 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 21675 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 085F944BBEC for ; Sat, 15 Aug 2020 08:48:38 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C440B68AFB8; Sat, 15 Aug 2020 08:48:37 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-ej1-f65.google.com (mail-ej1-f65.google.com [209.85.218.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 68E6D6808E9 for ; Sat, 15 Aug 2020 08:48:31 +0300 (EEST) Received: by mail-ej1-f65.google.com with SMTP id m22so12063868eje.10 for ; Fri, 14 Aug 2020 22:48:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=VKUgEFGlIMFAzr/mzgM21qLPuETJxuynakCf4fKehPM=; b=sakBAmhg2+dWG4R149mCU5pvtDZ/YgvFIRn2d7rU0LYtwYTydQhFR5vm0bJkseDLz0 povCLPz5z8M/m0TciKSv/FTDX9HDQug9mSL3LS51OY81TFhJ0Jyrhpo0bi/HDg4A0mU6 zrPN1IPK5MJwKsABY+5Uj0/ULyLir9D3P6q/HVyXcWOh75AeTYHGAbVLjR9yTgUI2Bu6 /ss9PkRXw7bI32eISaIrCnrD2GsqtDm1WhdU67PcxLqCLQe+A5/uRJA7BbJgEa+wg10q Bd4d6ruE5UwezEfG18VmTN44SP7OQlce0VukH6Ah05kreGcR0F+x+Qp1oWBTRQYUoK8C 1GTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=VKUgEFGlIMFAzr/mzgM21qLPuETJxuynakCf4fKehPM=; b=P9Tme+eMnnHqAllBpZGh/WN3cANHjJAhFk5/7RVBEaaiVhDVd8eQClAJrpYOQceJhn uYPIyOV7pmbdceKdSDUX4VHJsI7Ywj78omZeFPqdub2KlMn338awSSy42ZPCXKt4iXPr DSznXTa+gLkUZcVnJV4FJ8/mOhX34InphQkpG+B8Mp5a/XFYZNCfQYrt5pETAvnbiuhB Dr1ODB3BjcV8ar+LDcmrcZZpQ4cpS/KxZ/Lds1MMRGeOCd8/mpD0hbfMk73BhG6UESYR v+FyCVvQCZD2vK3QGVkbb9VPOqwehHFjwDGjTxUI3cHj/Xr0fMF29DNExeDKETFEY9uI bntA== X-Gm-Message-State: AOAM533cj9Gy9BiUlvaTNTSQ80dR5c6BbOq0lFSDUVZopKTKEn5Seb1M 8wgQAQdGgTRMdchN1wYtXrjU7YnF0bU= X-Google-Smtp-Source: ABdhPJx8MyAEExgoxR6SS1gG7SXLjV2d499b81Bris/n/biKiYeEb7eUK/PqU/YNSBKvsHdPUhBCtg== X-Received: by 2002:a17:906:2717:: with SMTP id z23mr5710010ejc.19.1597470510519; Fri, 14 Aug 2020 22:48:30 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1fb0f.dynamic.kabel-deutschland.de. [188.193.251.15]) by smtp.gmail.com with ESMTPSA id x1sm8086434ejv.11.2020.08.14.22.48.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Aug 2020 22:48:29 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 15 Aug 2020 07:48:10 +0200 Message-Id: <20200815054816.375-1-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/7] avfilter/formats: Make check for buffer overflow redundant X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" and remove the redundant check. This check for whether the allocated buffer is sufficient has been added in commit 1cbf7fb4345a3e5b7791d483241bf4759bde4ece (merging commit 5775a1832c4165e6acc1d307004b38701bb463f4). It is not sufficient to detect invalid input lists (namely lists with duplicates); its only use is to avoid buffer overflows. And this can be achieved by simpler means: Make sure that one allocates space for so many elements as the outer loop ranges over and break out of the inner loop if a match has been found. For valid input without duplicates, no further match will be found anyway. This change will temporarily make the allocated formats array larger than before and larger than necessary; this will be fixed in a later commit that avoids the allocation altogether. If a check for duplicates in the lists is deemed necessary, it should be done properly somewhere else. Finally, the error message that is removed in this commit used __FUNCTION__, which is a GCC extension (C99 added __func__ for this). So this commit removes a warning when compiling in -pedantic mode. Signed-off-by: Andreas Rheinhardt --- libavfilter/formats.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/libavfilter/formats.c b/libavfilter/formats.c index 04b8c7cc39..1df0c347f9 100644 --- a/libavfilter/formats.c +++ b/libavfilter/formats.c @@ -65,7 +65,7 @@ do { \ */ #define MERGE_FORMATS(ret, a, b, fmts, nb, type, fail) \ do { \ - int i, j, k = 0, count = FFMIN(a->nb, b->nb); \ + int i, j, k = 0, count = a->nb; \ type ***tmp; \ \ if (!(ret = av_mallocz(sizeof(*ret)))) \ @@ -77,13 +77,8 @@ do { for (i = 0; i < a->nb; i++) \ for (j = 0; j < b->nb; j++) \ if (a->fmts[i] == b->fmts[j]) { \ - if(k >= FFMIN(a->nb, b->nb)){ \ - av_log(NULL, AV_LOG_ERROR, "Duplicate formats in %s detected\n", __FUNCTION__); \ - av_free(ret->fmts); \ - av_free(ret); \ - return NULL; \ - } \ ret->fmts[k++] = a->fmts[i]; \ + break; \ } \ } \ ret->nb = k; \