From patchwork Mon Jul 8 22:24:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 50426 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:612c:fad:b0:482:c625:d099 with SMTP id kf13csp32618vqb; Mon, 8 Jul 2024 15:34:13 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVFgaLU0hqjcHSDqssb/QlPcFMrOCifmqpog0Hm+ebrzz6NsNO274wQBq/NYk2xozLfGIbP/H9LnnsVKc2roL+3AONwOBAgPNP2Jg== X-Google-Smtp-Source: AGHT+IGBgne9iyChnoanqGUM/mkY2PhjJsUpuQuzSMGHBRu5THqme02ZqZUgDBKDGyUtBsla5/c6 X-Received: by 2002:a2e:9693:0:b0:2ee:4c2e:3d3b with SMTP id 38308e7fff4ca-2eeb30b4c53mr5420321fa.4.1720478049472; Mon, 08 Jul 2024 15:34:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1720478049; cv=none; d=google.com; s=arc-20160816; b=DkSzLp9ck8YE8gKybBbbytoYDBsiscwfDBTpVX1K07LIOx+neNk+i/vQ1UVyNfrJMh dtSd42amoSgHHpw+QcqHx70ooes9KCqNfSECRag7uVT6Za90ErxVPMwBp2tOy+KL+pPS 0ILPI4vboph6kIYMdCPVFDjfpEoNRxDrMrIlRiMCL1UMR23nz/L+usyLnLZH/wb8tmaw BOFoEqA24g/Wd4xsbI6VcN+dI9D/b4qBE+q0pVZ/Ilk1g6HKOITPfIEc8jDymPyi5Iff iTAjPLDBlDKsj/JlrjxJivZVW7PNzPlmdbpLwGxSKJ45e642091vjLHOBSnLCdvNhVzU qwdQ== 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:dkim-signature:delivered-to; bh=RkXgQ5VLZzZSHlBG+Dlx9rtGHjaPqtswDAVFDxeAsBQ=; fh=e5zN9xSzcxLA6bGo3lF+CqTbY/oLwzApV03EO/RBfgQ=; b=DsImoxKOxTcl2XgrXQkSFC/MWP0hy/EN5XX2is+0zEX6GbpayFbNxM2SzF5YsmpPX+ 7cAhGYvxxpT5U+eo02Jo57AsDk6qcR/cceBUur7rtUffk97Sx7tQTWTQZ7r7G5juc1F0 E4Torn2krVrOrlIKxn9hK1izkXS0FuK5aW2swjAwsw7zDnfh2u+bxQc/Qp3AfN/OU5Om gkgPfJ8PnGTlkXAczlrZ8hVVO3wAzy8LQw4H+vyUVWfjWhn9XzAAdPErnOmEGJ1Ztu++ MbWb7exsPTOFqv7K+IHTVML8/8918DgFfiuoQ8NNGdVebSiqjinFS1ALLUyKhr7ABJye RPHA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@niedermayer.cc header.s=gm1 header.b=j7jx4z+j; 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 38308e7fff4ca-2eeb34a0771si1282651fa.538.2024.07.08.15.34.08; Mon, 08 Jul 2024 15:34:09 -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=@niedermayer.cc header.s=gm1 header.b=j7jx4z+j; 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 1981D68DCCA; Tue, 9 Jul 2024 01:24:29 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay3-d.mail.gandi.net (relay3-d.mail.gandi.net [217.70.183.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 77CA868DC22 for ; Tue, 9 Jul 2024 01:24:18 +0300 (EEST) Received: by mail.gandi.net (Postfix) with ESMTPSA id BD9BF60004 for ; Mon, 8 Jul 2024 22:24:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=niedermayer.cc; s=gm1; t=1720477457; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=u/kvRYIZsI9AL6rNOXoLTRMqM6Q1D/yTtrljbkFGL+A=; b=j7jx4z+jyIozPVDwiC40+T4lcrUZcdEKZLPy3h8YGXhYfanQQ25ThaNHEZu6REwpjzLVoq V0A3LxrtFAjwHoou8IqqSpYJW/ZY5GU/UfF0FvVdGZYXVijolgTFA1h4MsVlDjjZ8tp69s nxnGMuNBS2lXRh3ialdM+hZluzMSZz9T/zOe4HtI50/jDBOFqrtB+snGtSP41JunLzXNqr nXx+tdCoePpj0JyFZ+E67+w3b7ZjlTEgLUonuthFTO2qHiOiamYbbbcN6KwsDujZK3kccA Ij/8t779jcENARzRa5vPzezyKySdlO3uCD/fw0A4SCwJjFmzBhPNhFIq8VyDZg== From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Tue, 9 Jul 2024 00:24:08 +0200 Message-ID: <20240708222410.773456-6-michael@niedermayer.cc> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240708222410.773456-1-michael@niedermayer.cc> References: <20240708222410.773456-1-michael@niedermayer.cc> MIME-Version: 1.0 X-GND-Sasl: michael@niedermayer.cc Subject: [FFmpeg-devel] [PATCH 6/8] avfilter/scale_eval: Use 64bit, check values in ff_scale_adjust_dimensions() 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: A7rqDzpHdJ29 Found by reviewing CID1513722 Operands don't affect result Sponsored-by: Sovereign Tech Fund Signed-off-by: Michael Niedermayer --- libavfilter/scale_eval.c | 9 ++++++--- libavfilter/scale_eval.h | 2 +- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/libavfilter/scale_eval.c b/libavfilter/scale_eval.c index 75ed503f15f..dc8d522b1e3 100644 --- a/libavfilter/scale_eval.c +++ b/libavfilter/scale_eval.c @@ -114,7 +114,7 @@ int ff_scale_adjust_dimensions(AVFilterLink *inlink, int *ret_w, int *ret_h, int force_original_aspect_ratio, int force_divisible_by) { - int w, h; + int64_t w, h; int factor_w, factor_h; w = *ret_w; @@ -149,9 +149,9 @@ int ff_scale_adjust_dimensions(AVFilterLink *inlink, * unless force_divisible_by is defined as well */ if (force_original_aspect_ratio) { // Including force_divisible_by here rounds to the nearest multiple of it. - int tmp_w = av_rescale(h, inlink->w, inlink->h * (int64_t)force_divisible_by) + int64_t tmp_w = av_rescale(h, inlink->w, inlink->h * (int64_t)force_divisible_by) * force_divisible_by; - int tmp_h = av_rescale(w, inlink->h, inlink->w * (int64_t)force_divisible_by) + int64_t tmp_h = av_rescale(w, inlink->h, inlink->w * (int64_t)force_divisible_by) * force_divisible_by; if (force_original_aspect_ratio == 1) { @@ -173,6 +173,9 @@ int ff_scale_adjust_dimensions(AVFilterLink *inlink, } } + if ((int32_t)w != w || (int32_t)h != h) + return AVERROR(EINVAL); + *ret_w = w; *ret_h = h; diff --git a/libavfilter/scale_eval.h b/libavfilter/scale_eval.h index 2eb6970aad4..b4895284043 100644 --- a/libavfilter/scale_eval.h +++ b/libavfilter/scale_eval.h @@ -41,7 +41,7 @@ int ff_scale_eval_dimensions(void *ctx, * force_original_aspect_ratio is set. force_divisible_by is used only when * force_original_aspect_ratio is set and must be at least 1. * - * Returns 0. + * Returns negative error code on error or non negative on success */ int ff_scale_adjust_dimensions(AVFilterLink *inlink, int *ret_w, int *ret_h,