From patchwork Sat Oct 5 18:58:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean McGovern X-Patchwork-Id: 52062 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a59:938f:0:b0:48e:c0f8:d0de with SMTP id z15csp1130456vqg; Sat, 5 Oct 2024 12:24:07 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUWaP5t5W0yVGPh+CR1T4H1GXPx9D05gBYJPuXDICLFbDoGaC4AIc0214tobqj74hhZY0NmoCSyQcsE3btLdd4r@gmail.com X-Google-Smtp-Source: AGHT+IFp1BG6V0/Bi2uLzp0nVmAGqcF2OpBuLVe1/Ee3qisPECx+rbg5e+h2WYq6nfOu3iIiUjiS X-Received: by 2002:a5d:4d0c:0:b0:37c:d4f8:3f2e with SMTP id ffacd0b85a97d-37d0e8f75aamr3550239f8f.55.1728156246804; Sat, 05 Oct 2024 12:24:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1728156246; cv=none; d=google.com; s=arc-20240605; b=a3ZmIS5XC8zcoviCNxuZmZagAlz2iYPrJ5IFJW4MK8jtxTiKAr1+Sascc8pCxA12fy /cXkRqh/GJezv93P8JujjHkQq4HVIApV1fR/ZuHhrncJNGwQAepVzuHAOsuPa4aDCH5Y u3JeQtbS4pcE4YyLfvwj/E+NhKk3UtXLg8nVLfauI1RbtmzhAg+0vspD+j6Vl9k51WP7 5t7zSdYIhpn0kb+hWOa36Ji126wWF0kEnxkyKKNtAO6pGvJG8aDoD7tNvoctCBrgf1u4 Ez84LSZ2k1iRIk7zWHgrk1xSRSykF/7APVqv2AfFd8bm+0UCbMYftla0zSBB0Fw4l59R MnBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; 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=N6gw5+nwiYSOkpRCMYA/G1I/7nNcbFty1N6+6t8v9vQ=; fh=YOA8vD9MJZuwZ71F/05pj6KdCjf6jQRmzLS+CATXUQk=; b=PFk7Fe2CiOOSwQ3znwcXaoEIRHLhmrpFGCKewPjpdGqHSnzitKVIPZ/oOMf2oIybYW 6RN2mlPuzjkm1C+IL3YPeczCcc8wZ0eGR64KOy/4wLnEB771Vyp8ksG9Rdz/wG/UCAjl wVaUROZlcQolkAcXKrE+59grKC0/6Gk74p+NgII+v2kqIicKRavxconXvECRMVMx7u/c SICNt19Itn1rOFqyvW/Jpal3PGO1EmCiMIBNiOUg1com1pOQ6AIifLqBK0kFiPlh/jzH ynNXc83o6m+sXP4brzsuoGd1qfps1p5OysNXGt7hMeGf9hTPoOV5jBwbMHsV9zm1EgQn 7/Lg==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=dHAK2NI9; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com; dara=fail header.i=@gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 38308e7fff4ca-2faf9ab058asi6485721fa.52.2024.10.05.12.24.06; Sat, 05 Oct 2024 12:24:06 -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=@gmail.com header.s=20230601 header.b=dHAK2NI9; 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; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com; dara=fail header.i=@gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0150D68A972; Sat, 5 Oct 2024 21:59:06 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qv1-f43.google.com (mail-qv1-f43.google.com [209.85.219.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 92B2168D6A7 for ; Sat, 5 Oct 2024 21:58:59 +0300 (EEST) Received: by mail-qv1-f43.google.com with SMTP id 6a1803df08f44-6cb3cbc28deso31430536d6.3 for ; Sat, 05 Oct 2024 11:58:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1728154738; x=1728759538; darn=ffmpeg.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:from:to:cc:subject:date:message-id :reply-to; bh=NWPEw48K6+nW++/orIqOrLWbRvTBWy/Z2IEb/BZo27k=; b=dHAK2NI96ov4cAmbIJxr+/lVhuWt6naPB5nL+s3AD7MW6DGqfWCTMGOoqBzLJp1sIE PjnxoX4Rw4K93ia/Vxk6+5QVhow3ZzvlJODI3zvDbwWWMNqGMPBL6/A9BolRuFrct6Wt wLMyEEgQ2TiC0bwlSVXOWz899iOTkvnH3JyhphhiNtAAHO3sT4KmJfENPUsgJZbW07Ed yfMbMAPByRDIcgIV6kMLSgYRKjQJs8GqimSf/sfl4vyOOWp/XMlPaoenu0TBDhE4UH8Q F5kTPTVuyHenqy/tRWbsmSrZHgYJuEvG71x+jA4m3IHK1UDveyJgYH+Ke6yxrcgCavt/ zhhQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1728154738; x=1728759538; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NWPEw48K6+nW++/orIqOrLWbRvTBWy/Z2IEb/BZo27k=; b=NuU38hyLyiOYYEhQiJmIt8Pa+21YNYAq6kkCjEhp3NMte+zYZ1FXJMI4RYwUThx3/8 uRKFxjyTLyGBd6LFIl5h0lvG3jZl2jpRuV8vlR3LoFBW5q+TNMTQK6CEccZijGH7SVSt SwT/UIXXFKokbHOuDk3zoWEaDZDymo0hW/zgiEplosToWTzFybwNapTyrxIf2hx4Ewgs Lh9e3ScOFNMuA7g9PY1xi7NUeS4/aMdZBB+k41lYdBH8qJgMz9JOd9rWBoLLJyqCFDHI dUEGC4Rxx64HSFtvhHV7LMWc7EyM1xfDWLvyLIYu2bfqh2SQJ+FUF/smIp4HI1aGUYPJ y0nQ== X-Gm-Message-State: AOJu0YywXANpWioUsvSr8cMsAsHLCOV0uv8dmOeu3R58rmshZkb9p5CX 61Nmy7TnZS+p8jFpI7W17Ecr1tn+euEJRar7pdaGTcTsDpVN8lezlcC/u7aO X-Received: by 2002:a05:6214:5413:b0:6cb:4362:e49d with SMTP id 6a1803df08f44-6cb9a490b8emr94413596d6.41.1728154737574; Sat, 05 Oct 2024 11:58:57 -0700 (PDT) Received: from elysia.seanmcgovern.ca ([2607:f2c0:95cd:5a00:77da:5205:11bd:bcbf]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-6cba47742b5sm10499436d6.141.2024.10.05.11.58.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Oct 2024 11:58:56 -0700 (PDT) From: Sean McGovern To: ffmpeg-devel@ffmpeg.org Date: Sat, 5 Oct 2024 14:58:50 -0400 Message-Id: <20241005185850.834379-1-gseanmcg@gmail.com> X-Mailer: git-send-email 2.39.5 In-Reply-To: <20240225184429.2962707-2-gseanmcg@gmail.com> References: <20240225184429.2962707-2-gseanmcg@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v2] aacenc_pred: prevent UB in ff_aac_adjust_common_pred() 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: d8SDqiTABoxm --- libavcodec/aacenc_pred.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/libavcodec/aacenc_pred.c b/libavcodec/aacenc_pred.c index a486c44d42..a6dfaa25fb 100644 --- a/libavcodec/aacenc_pred.c +++ b/libavcodec/aacenc_pred.c @@ -153,9 +153,7 @@ void ff_aac_adjust_common_pred(AACEncContext *s, ChannelElement *cpe) int start, w, w2, g, i, count = 0; SingleChannelElement *sce0 = &cpe->ch[0]; SingleChannelElement *sce1 = &cpe->ch[1]; - const int pmax0 = FFMIN(sce0->ics.max_sfb, ff_aac_pred_sfb_max[s->samplerate_index]); - const int pmax1 = FFMIN(sce1->ics.max_sfb, ff_aac_pred_sfb_max[s->samplerate_index]); - const int pmax = FFMIN(pmax0, pmax1); + const int pmax = FFMIN(sce1->ics.max_sfb, ff_aac_pred_sfb_max[s->samplerate_index]); if (!cpe->common_window || sce0->ics.window_sequence[0] == EIGHT_SHORT_SEQUENCE || @@ -164,7 +162,7 @@ void ff_aac_adjust_common_pred(AACEncContext *s, ChannelElement *cpe) for (w = 0; w < sce0->ics.num_windows; w += sce0->ics.group_len[w]) { start = 0; - for (g = 0; g < sce0->ics.num_swb; g++) { + for (g = 0; g < pmax; g++) { int sfb = w*16+g; int sum = sce0->ics.prediction_used[sfb] + sce1->ics.prediction_used[sfb]; float ener0 = 0.0f, ener1 = 0.0f, ener01 = 0.0f;