From patchwork Tue Jul 5 20:26:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 36684 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:8b27:b0:88:1bbf:7fd2 with SMTP id l39csp3728382pzh; Tue, 5 Jul 2022 13:29:01 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tg1u2XyzM9n2JzkXASokosohVOmYQ0jAJLTwsyw0eL2FIDsPgR+jNcpSTSUoR/q3nkpfbD X-Received: by 2002:a17:906:7386:b0:715:7024:3df7 with SMTP id f6-20020a170906738600b0071570243df7mr36218082ejl.543.1657052941586; Tue, 05 Jul 2022 13:29:01 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id h22-20020a056402281600b0043577827670si21696094ede.354.2022.07.05.13.29.01; Tue, 05 Jul 2022 13:29:01 -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=@outlook.com header.s=selector1 header.b="Zq0/GIBw"; arc=fail (body hash mismatch); 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=outlook.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0265768BA0D; Tue, 5 Jul 2022 23:28:53 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05olkn2087.outbound.protection.outlook.com [40.92.89.87]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 9C91B68B9A6 for ; Tue, 5 Jul 2022 23:28:45 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=TV1FeVfaqKKkFoqrJXjqN9YBx/EUHb3mKzYd+Z7gV5THQK5GVlBDXCFwJFTwjVbHUiF8ZZ7x6CSEZUREnXbTFLCrb/efnbJWDpnNbVTSt2JvaR6npsBFBwXIZ0PKAaedR00+lnTsf+S2rm6PtKO7t3719tBr07tNwGhzk7YsnQcgCXFbnJFASXpPYuRmx8KLYwLnoBQ7VLUhtW8W2jjc/H0tBohsll4N52dP379+9/vf30Ry8tv3LVy69kZ6P3be9PiJHQ4NwOrt+tOS/X11T3/Zhk14WgoIESXAziIW1U1orvpvDv/V+c6NMrcgGLBXNrtW/iG5j12DAuKGYcsCsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=U/03F+QcRYP4aQArGEnbPzBsN2g+1EyBvJn3glj4RR4=; b=DWoaWAdcG+XdP0ig2CIow3C8ErNgEjxs6uoOFvzrTonS4KW0VwAcZlO7lrut9pJ6bFQnNvaC+2Wg/HJccqmVNzt5iaP0b/PfMDzMedUtm5UFQzTZ0KcR3A7/XlOalEEAMlSe+z30hH80Wwp5bYh8bh5MSMD1KDBb419uOz+QXyhIVq4/8775X2KB4Rkj2rM14vkSb0Fqe0DXBS+3ZauOJN1mtmsksjcqnnPgVgiZGETBDtc+76soZOJ4pRlxbvGvdOm7+CwTm0IbeJArCb5+zN1cum2Y8315ubgSTiEibFR0FD7VnXKeJ+S6Rs7u7PZTXIC3l0O9G+txRP0m/1XBQQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=U/03F+QcRYP4aQArGEnbPzBsN2g+1EyBvJn3glj4RR4=; b=Zq0/GIBwza62DVPsUgdVUpMe2XKqjdhGdceH/hPcb0d/HV9X2uAC/rVYUqdGhTN9fawoSjZT+1uDiwSrrIFs/Xkn1gaNLgw6p9AzQASKl4Y7HfqeBFv8+1rtu8mUjC+opuDUReVhz7d8Ar0cqEc7yNNtni9PKoI16UenKtOk0EHoWKHRY2puMEASwVDuS52Q4AxH4xSqnWLAsmXRBGu6gV56dLRGaYT3QXfP7sSeQoq+r5X6V0cB8hPAXRP3cSdbeaVBq7/z9x28OKW/5mrORrbn9DZctDSi+XcLr4UdRe/FVjOc1+d0hwkvIjq+YiHlKgqAIwxbeEVNSS9+q6hFiQ== Received: from DB6PR0101MB2214.eurprd01.prod.exchangelabs.com (2603:10a6:4:42::27) by PA4PR01MB9452.eurprd01.prod.exchangelabs.com (2603:10a6:102:2af::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5395.21; Tue, 5 Jul 2022 20:28:40 +0000 Received: from DB6PR0101MB2214.eurprd01.prod.exchangelabs.com ([fe80::60b9:9f29:40cc:f01c]) by DB6PR0101MB2214.eurprd01.prod.exchangelabs.com ([fe80::60b9:9f29:40cc:f01c%10]) with mapi id 15.20.5395.021; Tue, 5 Jul 2022 20:28:40 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Tue, 5 Jul 2022 22:26:48 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [LQpDIOndOABmpgBoq5V6MqnfYOK5r4ID] X-ClientProxiedBy: AS9PR06CA0419.eurprd06.prod.outlook.com (2603:10a6:20b:461::15) To DB6PR0101MB2214.eurprd01.prod.exchangelabs.com (2603:10a6:4:42::27) X-Microsoft-Original-Message-ID: <20220705202650.797218-5-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 1d6191b4-e14c-4c79-dd95-08da5ec4f2b4 X-MS-Exchange-SLBlob-MailProps: q+fD6XS3/UJvtnGI0O/xt+lrjf2qTxdNzAAa/sTSAXBhQZtLxrykjmjQKB6aPIA0b4ezTMEYoiBFxPQMqJeMGVDApUtcW+PT8WvxIVhxX/zfjdfvNqk9Y1EDl+ByycvdY6tejNHpQetgclL+jMExBJIogMeEzbYQjZp3K1qiMa0i6Ij8GpbEKqZzxJJwYg1K3Sw1THH90w63dO/8s3nsfn97xyjC6afYa+xt6wY6xhfWwJdPxXz3fHRmW1h6YJRPCyfCOUj8IlExfo6sDPEhlLmfTkiYVH3nDijVK6QfC526No1TIuJYBxQ7e7nLhM4+cUxZxHfTLig5X2B8Ls+7dgJGeQ58YEoT/N/KFYnj0tLlcNghUiT29beJu1uBrjzi9LqymA+ILw7i4dkOL950aC2W6251bGekJ6Jj1lqdGpno5IQTw1rF4cLuaFXo/TJzoUeK4kbAZesxcphqfIdLwKm54OAL97c4hQlj+wtu5fJSrDnhmE7yF8ZnX0GvBc/lbjGRTwZb8t7/3RvJkO254hhkQ4CeWXev9rcbKxdmHuGHtE7PS1yAl9jRT+YlLpLAXmnaRdS/N6BTPojSe+MCa3WCBCyxG51Ij0MbywGVvMCBDGI667+YbL9UwXkpBFnnAuREvovuznU+yFkm7O24N0Y8/PGJf1DPAEnMJjVrA/33v8FO7YkwnH1xkqSqDJSjixnleOfb8VdDfU7RMGqo/A== X-MS-TrafficTypeDiagnostic: PA4PR01MB9452:EE_ X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: zjGAUnE1ooRmKqQysr+nLrUelNtHkBldQSTaMkSy4OlxvpLA0EKI6bCBNoGCbn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I8oHSJLr8L+86DvtSFKcTfV8zEZCd1TBn9z/ptO6At9AgoKtLInMftlq+05wD5EpKXQ79AhYIlGAG+fsoyMc5M/Gthxqckc2DqxY52g0T9QTG2Ms2sYM3AxaIfYeoO6emg8YrhCpjrLNX6LSwdSlv4Rd8NVHhxeWM5bCoNhCvaqD+PsZ3Siq0E4tbK8DANrR0z3SXujWT4DecJrGQeYW/ZY+Yuto5VcHxVEuXhvDvtU7TR94kJYdtBU/vqsYTQLCeevJKbpzJikCxLNaLoleVV+xBCovriixGpN1sv24JV/W2skBBYPtQTunznpjRaC6L4tJAFX2VK15NKMOssIc6Jl/mw8SuhYP66KVvPZSQheZnUSqloT3nz/iCh33OJP/0gbFG+F0JyrUn65MwNMt6XuhSbeq5yNcEipkFNNK0fFFGslTayyRj2dgEqS/KvrSUch3MATNfOHfruWrN0ThyWHaQiD/zkenekr+TpPHXJLdeCDTKnzhSJkEB6XErHZF6ltx16FHcFnIRrtduSLvcTB8wmS3qsxM/TGxX4mSU/mJrAtHygv6VhfF3uk+/Djlvr0xqP4pn9+l8tp4//12RrN6w8qPPqRhKI87laDrbjXvGP2D27FhebZP9LXYMWbYKkxncd0cf7QSXBFRyJ2INmwQFUcDuuMP5Hy2+Ep0RzRvqqiOBMj5ev5edQxSAg52+23lzmU7DjRkpt2HlTvM5CE9v1tM36blvFrg6IRHDmHg44bOg2GuXBNZGwG1/LxWJG1g19b1WkTtmVq1ipJyr5Cqs25LVmkT7mH1x7itVb3gfxxlkIk1CKkB8OSEY5gvx2CajAu2thlmHgPDKlurVU6b/x99K/ElRNim/9TBmeR1E6j4DtKISLchLRaisVX2xWkPbMA= X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 1d6191b4-e14c-4c79-dd95-08da5ec4f2b4 X-MS-Exchange-CrossTenant-AuthSource: DB6PR0101MB2214.eurprd01.prod.exchangelabs.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Jul 2022 20:28:40.7840 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR01MB9452 Subject: [FFmpeg-devel] [PATCH 6/8] avcodec/movtextenc: Use av_fast_realloc_array 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: C7zptvwywB1N It has the advantage of not overallocating beyond the maximum amount of entries that can be potentially used (namely UINT16_MAX). Signed-off-by: Andreas Rheinhardt --- libavcodec/movtextenc.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/libavcodec/movtextenc.c b/libavcodec/movtextenc.c index 728338f2cc..fb19b110b4 100644 --- a/libavcodec/movtextenc.c +++ b/libavcodec/movtextenc.c @@ -76,7 +76,7 @@ typedef struct { ASSStyle *ass_dialog_style; StyleBox *style_attributes; unsigned count; - unsigned style_attributes_bytes_allocated; + size_t style_attributes_allocated; StyleBox style_attributes_temp; AVBPrint buffer; HighlightBox hlit; @@ -342,6 +342,8 @@ static av_cold int mov_text_encode_init(AVCodecContext *avctx) // Start a new style box if needed static int mov_text_style_start(MovTextContext *s) { + int ret; + // there's an existing style entry if (s->style_attributes_temp.style_start == s->text_pos) // Still at same text pos, use same entry @@ -353,10 +355,9 @@ static int mov_text_style_start(MovTextContext *s) StyleBox *tmp; // last style != defaults, end the style entry and start a new one - if (s->count + 1 > FFMIN(SIZE_MAX / sizeof(*s->style_attributes), UINT16_MAX) || - !(tmp = av_fast_realloc(s->style_attributes, - &s->style_attributes_bytes_allocated, - (s->count + 1) * sizeof(*s->style_attributes)))) { + ret = av_fast_realloc_array(&s->style_attributes, &s->style_attributes_allocated, + s->count + 1, UINT16_MAX, sizeof(*s->style_attributes)); + if (ret < 0) { mov_text_cleanup(s); av_bprint_clear(&s->buffer); s->box_flags &= ~STYL_BOX;