From patchwork Sat Nov 20 12:06:31 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 31513 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:d206:0:0:0:0:0 with SMTP id q6csp3916323iob; Sat, 20 Nov 2021 04:06:56 -0800 (PST) X-Google-Smtp-Source: ABdhPJyVjKAK0PTLLZGi6RxDatL48XyiAoF67F4emyJK8y1fyzQsazYTlAvnfst17c/V5DAScoOQ X-Received: by 2002:a17:907:6e8e:: with SMTP id sh14mr18929005ejc.536.1637410016656; Sat, 20 Nov 2021 04:06:56 -0800 (PST) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id gt14si7392387ejc.495.2021.11.20.04.06.55; Sat, 20 Nov 2021 04:06:56 -0800 (PST) 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=CIhqQ46p; 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 D40216802C3; Sat, 20 Nov 2021 14:06:50 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-oln040092075064.outbound.protection.outlook.com [40.92.75.64]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 18E536802C3 for ; Sat, 20 Nov 2021 14:06:43 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mwWh7jofu+x2qw+x54EHAHakkE9wvizF3MKaVdDRpBspMSak9CET7ODOOzD72WH1sA19rmSzRWMoRH/WG5cOPnHaBABJYBvsRcSxD3Xb44FzN0Sz1F34aF8S6TbWgyGN4ex8/4BAVDBWGbSdVEgOrLWWcD1TzcVdYg36Q/eC+H4AwqY0mYtOEKchiG4QrUcUFHk5bICXuUl1/OIdaDaL5kD12+4+8EE/JJUfU1SBEtYcdNIEKIQ0s97uTcXDYAbqItJwUpB7pfzfkhT9m/T4uIMkO+ngww046wZeaLT2AmBtB/+fgazf37O/eEV9rXcjAdFyFFniTk2Y7slJJuM2GQ== 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=rUKAoCsb9qAuCWR6qoDtLJyfEIrp6fxAQYUeJ5qyUjQ=; b=A9RUkFObdFS1OaCzcNB3m1C3tvZbJqZtN+gmtASjs1SKeiDnF32VeGf3YZ/776/L5jFyhPXtrS7pADUYXxGKzunmLNxp6EsUIwiGvpKon37/BN79cN7rjSDeqZ6XBkTaHnWtGfheZBmy/36/WqJBW73l1BZe+k1OnpQ1LR16+bUFdf9SWUPiqOg9PJJwiUydSFBzuXG+SDmNJYL4AyA3xpEzMKct478C/kMvha40NrAxZegZVzUgh6gh50Wmdw3XP1WqMO1e3gj+twI3NvqPPYnpkyw1w9kaeSvMWBP64C8B2q104exRuexRH0WEPAQIGy6zxjmuCdQvRfADkGvtQA== 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=rUKAoCsb9qAuCWR6qoDtLJyfEIrp6fxAQYUeJ5qyUjQ=; b=CIhqQ46pKiqmpOVJ5mZCHJ9SfiMNIEajmuqbNE2+qnbdqLW+yQ1HaCVFrchAveleZiDcG23H1gDjtw6Iav2BLV6z8IXGNwBjpCRDtXiOwpl0znn1PCDSLLzJ5A3n8Ep9/T6Y2DbfqXEhYwIUkjOxf4rCfOHFF/vKXGm4j7xFyVG+PRkvif15MsV7ClEsZj1ob/2DqDy349HYFoZ0rGI9J2Bbt0faz4xZW+D+MH738XWwIGT8lV5Cjgnp4kclFM7janIcRUEWtRoptmuajlErOH8RBdUqQG8vW0TTuUJoVgYAb+E+ogAaaH9miJrLtgW07pnNCTVVDTBlzn06V/ImIA== Received: from AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) by AM6PR03MB4215.eurprd03.prod.outlook.com (2603:10a6:20b:e::27) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.22; Sat, 20 Nov 2021 12:06:42 +0000 Received: from AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::700f:d70b:3bb8:4d51]) by AM7PR03MB6660.eurprd03.prod.outlook.com ([fe80::700f:d70b:3bb8:4d51%9]) with mapi id 15.20.4713.022; Sat, 20 Nov 2021 12:06:42 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sat, 20 Nov 2021 13:06:31 +0100 Message-ID: X-Mailer: git-send-email 2.30.2 X-TMN: [WSrhNRV7Ixux3Ddg84494zT7lcKdHD1H] X-ClientProxiedBy: AM3PR05CA0147.eurprd05.prod.outlook.com (2603:10a6:207:3::25) To AM7PR03MB6660.eurprd03.prod.outlook.com (2603:10a6:20b:1c1::22) X-Microsoft-Original-Message-ID: <20211120120631.1278322-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from sblaptop.fritz.box (188.192.137.12) by AM3PR05CA0147.eurprd05.prod.outlook.com (2603:10a6:207:3::25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4713.20 via Frontend Transport; Sat, 20 Nov 2021 12:06:41 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 00d77a34-bf0a-4ec5-f3f8-08d9ac1e36cc X-MS-Exchange-SLBlob-MailProps: EpEO96k6Wol9fKQIkSXRM3htBE+fuKykvUBWVjkGgOYM/Swtp1a0ITAc15Ey2v13o6CfNU5e73bGh4yx+RGyaNLd5wMr//IUt2xgb9ztOgc71Xv7CFOi3bYxzyYLaQXSOnFh7Ig/uCYiAK5kyifXhObamK7SooPWrimimjJYaO6bxAOAhMp8wQLjWGv7GZgr4HzSfBF7xwI0X0R/YUwwXoIG1F6kyQ+1JvuTsLzxekmTW98tZfVtGpTTv5M6CAcHYQj08sP1DMFIbAyzt8vQwOVBjtXg24m5hTbgM3V5+3O0ls3YOTajvt4jydLsw10zxfkMX1FjnN9UmvepsLdPVfrqKeFBekwXt9/AIyegUV2Xv7fZbDrWmi1gwtipKR6iqi5LxeHR6jYXCb9mWIL9dbNxUx4Mcw+SG9z0ojZ4Ap8kc5k8HSUkrBfPQ8DjpyUWf6clKoYsrUdQxuMMl/sBgf90FJmnWYV9Nc4i9KsRTjgFsztANGcFG7PfyGW/EX1ePREkVoduchBUJq4YOda1jkhvf7x/RRwzCAS1J0FOXjCCSwLM3uexreKwxx6cXmmX6puovawST6FU3dT5WHrOIUZBXsMh1ZwBaxcl4DVLcx9boUC0zoOaiL2ui5fpFH2izlVUUNV2In3h9afXxOD0giMHt5GYaBzJz+VxTMytTBrwU9gz3BmR4BkUYIZIHeWCw4hvaAiTTYEyVFS0Ik/AGsAsVgv54J3aJO5Z7QEp3fWZlEXCTrt5WhQS7PDBLseYeTGeIoQ9C/E= X-MS-TrafficTypeDiagnostic: AM6PR03MB4215: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: lbdZRcizCJAInzakccPOCYhZZugAtxwwMRxp1ufj1cWsngBtv0cdcgTNrbbbZPSB0Yv7oI05vqvLk2Wdm8UL2s+rLtg42/aaI+j00h7D9n/YsHjY6CBcWKGUO8IlgHBS8LEzzvmwlvbfchi5vjA+FUzNlLv80vGnCvUFk8rdnKAQNeAleHJIYXvL1vWfiYIO17XynXy1A64FC1otnEDFsqHcWMETyycNLrBfw2eaGtCqLnPaxML5rIAlD5ILxwt1goazo9Hek2W7cwYqiY/b+t2RQwFsu8VM+CsC7jv76mNoR5VMNHy9AxWlmfCqjRJqti9vqYF5MlGgBZ0aRBnoSBvZ/wW3BwO4N0lH+YRVJbXF6kBrAoK7mWTxHO7niKb5ROUWlJDrWpt8zpuN0CMsRdTKov1cmtcC7qA1YeSwBX8MWLQYNHV87+oK5Zf8W89BDxT02r+0BTbIUMWshTPdbL5NoCZBrFi+PX87J+VoPG+7/vktLIvGGetj5TFmC6kPDiX203nipw+dVpZEeGuhuzK9L1KzymqlxUpVjhp3jd7tTwkGwpcrvVzjktT8+q/sbiKOTL/wmoUhqCf8V9Dl1g== X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: PZA6jQzVYmab+tEvxb0FDpL90pp3O4G89VK0xUDCl/XXBy1AeastnA3oiGS3/ev3rhb8fsWrJg7c3k3pSro8nJshwgUxeclmMbi+evDfrYWlrXyXrUorraEkgKNpQ4xdp0x79bCc/I6hAxqNAASgFsU7EQdGoaW2MYV4aiW3hkS7bsCPbncWUiNLdE8DzqTLzF5fNq0zZXbd6ZW3yy5di6j4QAzXiO8nVyGV3RvbLHDoulPgyA7NG1WomwySdd+/pLbv2Qjt2SInsuevfSCS8mh8zPr8uXlkLwbM21BiEqba3UO8y0FO1uP1DFVHBw2ZYq5uBR/JYh+otcmHJLfCoFl9g+FSgGFqD4nMr43V+Py4MoS2YIhxQ+tK0Q9w3ov0Ohf903k9Fx0l4004tInR2ih0JLWylRUivtUnp2OFmS/9V7ucsGET8mEQGdlii+mw6YpxWZJSy2uOGiuXG/R0P/9KkZEK5QV4CDWzjfy+cnmpcIrAsfWflDFxKoHekJOsqTJGHIMAavDdbOxqlkTF2AYUm0BdMSJBBX5wJqGsEBllKPyHjFXC3gkdL++Fo+lEzC7ridnGZ324fD1egkZNBQyAiKtiJugWTRI/ZeG3rGqNHc2lNfoJu3+6Un/TveFdW7MY8l736h1Zei3nIZ8X8qxsG+cjImb4QDNWICednbmzcdFPlR8eAc39ibW8GMsgYJRViMZ6mMTWY84zCFz81w== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 00d77a34-bf0a-4ec5-f3f8-08d9ac1e36cc X-MS-Exchange-CrossTenant-AuthSource: AM7PR03MB6660.eurprd03.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 20 Nov 2021 12:06:42.0721 (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: AM6PR03MB4215 Subject: [FFmpeg-devel] [PATCH] fftools/ffmpeg: Take type limitations of AVFifo API into account 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: 59Yu/xOhd0N9 The types used by the AVFifo API are inconsistent: av_fifo_(space|size)() returns an int; av_fifo_alloc() takes an unsigned, other parts use size_t. This commit therefore ensures that the size of the muxing_queue FIFO never exceeds INT_MAX. While just at it, also make sure not to call av_fifo_size() unnecessarily often. Signed-off-by: Andreas Rheinhardt --- fftools/ffmpeg.c | 9 ++++----- fftools/ffmpeg_opt.c | 1 + 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/fftools/ffmpeg.c b/fftools/ffmpeg.c index c9a9cdfcd6..662cd7fda3 100644 --- a/fftools/ffmpeg.c +++ b/fftools/ffmpeg.c @@ -753,14 +753,13 @@ static void write_packet(OutputFile *of, AVPacket *pkt, OutputStream *ost, int u AVPacket *tmp_pkt; /* the muxer is not initialized yet, buffer the packet */ if (!av_fifo_space(ost->muxing_queue)) { + size_t cur_size = av_fifo_size(ost->muxing_queue); unsigned int are_we_over_size = (ost->muxing_queue_data_size + pkt->size) > ost->muxing_queue_data_threshold; - int new_size = are_we_over_size ? - FFMIN(2 * av_fifo_size(ost->muxing_queue), - ost->max_muxing_queue_size) : - 2 * av_fifo_size(ost->muxing_queue); + size_t limit = are_we_over_size ? ost->max_muxing_queue_size : INT_MAX; + size_t new_size = FFMIN(2 * cur_size, limit); - if (new_size <= av_fifo_size(ost->muxing_queue)) { + if (new_size <= cur_size) { av_log(NULL, AV_LOG_ERROR, "Too many packets buffered for output stream %d:%d.\n", ost->file_index, ost->st->index); diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 6732a29625..de6af0aea9 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -1637,6 +1637,7 @@ static OutputStream *new_output_stream(OptionsContext *o, AVFormatContext *oc, e ost->max_muxing_queue_size = 128; MATCH_PER_STREAM_OPT(max_muxing_queue_size, i, ost->max_muxing_queue_size, oc, st); + ost->max_muxing_queue_size = FFMIN(ost->max_muxing_queue_size, INT_MAX / sizeof(ost->pkt)); ost->max_muxing_queue_size *= sizeof(ost->pkt); ost->muxing_queue_data_size = 0;