From patchwork Sun Feb 18 02:41:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 46334 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:dda5:b0:19e:cdac:8cce with SMTP id kw37csp572867pzb; Sat, 17 Feb 2024 18:39:46 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXEnov698dfe7CYDxztATXOhyCs671QkPG3PVLDzK8vV3aSdC+9+G9pxa3jv0MICm0WAV3wBLllOInFjTIyB5fgq69mJo5U+bB2/g== X-Google-Smtp-Source: AGHT+IH4CTEHR5D2mmPasJ6RkmlNevdrLAo0sW58oBO5C9OmXMk4X0nTQFa/O1/08uM5ASaW5UIp X-Received: by 2002:a05:651c:548:b0:2d2:2e6b:dd5 with SMTP id q8-20020a05651c054800b002d22e6b0dd5mr1797862ljp.39.1708223986519; Sat, 17 Feb 2024 18:39:46 -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 m16-20020aa7c490000000b00563a6b8c24fsi1257302edq.53.2024.02.17.18.39.46; Sat, 17 Feb 2024 18:39:46 -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=BslHNl0H; 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 9C66768D314; Sun, 18 Feb 2024 04:39:42 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05olkn2059.outbound.protection.outlook.com [40.92.89.59]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 39F0468D164 for ; Sun, 18 Feb 2024 04:39:35 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=YDOHY5eK8V4p9i6BbOJ+/v8Or3UuVQVnDaQMFcqKeCmUrrpmMMxDXzhiY3A8XKkb2eDWShY+eqQWEltvWYvoMPjyK54hKKJDmUJGO1t9OJon9ZBgdblw1SytibEsAckDhJ+v3eY3oSeBPeVqXBgIRfaSQxc8rzg0B2J81A/vyhO11Z0q1SMI/91/2skqp3Yu5pTDT6yI/w0c9+2aIYOtnTNgASbxLtZKPL5t0ASNHF3MSrpmUOPXKr2L6oUWsCmtF5O7JSFi4iUpZ0Do6Dy9PjWlwhZ7ZR1T6lUXQBKhxr8aPrQvXKrvWBD6LBKBwcP2aqr5KLT0I8xJRLg1mHbIWA== 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=pbIzTvFTFTg1M6yIfqT6O1W776WVSIGr7fSMBay21/k=; b=Xsp23JlvxBGL7nADrvY18eCmdTPPM/8E1JFmlr4fEaGH24RFArM165WxmJE00LAzuU/NmldE6Dm8VizZ28bKy5lLMaUaqICgZIJzFuOrvYbheBV56m7SGjU89EX1wdwuNfDV564v3wAKIkfb5RGlYWyBH0kYw+UFcw87a4MtEoLPOSaDIn1DdoLxXg54c73d1pJuM5a3TYhGn2gpe6FDQdmd/Ia+LwCR3aPk55mYcj1YvTS92wZNW3KbNcyyNjsAgevC17x3IFF9pcpv+Hs4RG5eO10ISAYqpz9TCKXvq3sRGHu82FQSl9l/V75hjKhwguhZownYy8cG4AvP2QpTcw== 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=pbIzTvFTFTg1M6yIfqT6O1W776WVSIGr7fSMBay21/k=; b=BslHNl0HT4w8XE6Ry4Ii24s5LFKU6SkLnhi4T+1DrC4mB+lIh6kR6H5SQbUPWwiiSRFcAqAmt0WZBdw39OuB5CtFYTPMxV0Y7oznCLKicIw+5zf4rdP+VyZUFKD6DMndHo6uzFrEjVpgv/1ZhvO9w0NkyvtIhSWboCcKjKxGAYhqe7iC8yGp0HtasZZHG7bustP36JUyruottYeXfzS6fA0GYjqPRWVi256L009x6FYIjynITDHCx9ENja7bKTTQ/ciOoYC15oAgcRPR26SyMjWcpxG4j8i4wYteoYTpCvbgzk+DgVKIejZdeQ0DzPwpt2oHvc/kpvUXqCxqvIxAzg== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by AS8P250MB0054.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:359::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.32; Sun, 18 Feb 2024 02:39:33 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::65aa:deb0:a18e:d48d]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::65aa:deb0:a18e:d48d%5]) with mapi id 15.20.7292.033; Sun, 18 Feb 2024 02:39:33 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 18 Feb 2024 03:41:18 +0100 Message-ID: X-Mailer: git-send-email 2.34.1 X-TMN: [Z+cqevV5242ciOYefVk5Dg+EqaNs6e0KgNYwArGtZ1M=] X-ClientProxiedBy: ZR0P278CA0094.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:23::9) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20240218024122.3102927-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|AS8P250MB0054:EE_ X-MS-Office365-Filtering-Correlation-Id: 84af8fde-b71b-4ba1-24bd-08dc302ad684 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 27Q+NWsBdWSb5bAkRKkncmQER4Gr91unGPql2pE9wBZfL0HFeChOGidP/bGbeVWhZTnbRuZEke4Unef2wpTXh4g+y2Scv5dUrgPGaqcpLKNKDOHqT0zJqYFsolQMfupAun+YYXlEtDdnABEj1ozZ/nONeKr8pKfKjHze2NQkkTw8Sjf+oomjF9xE3QT7l8Y3LVLXhmJ37AQm0iyHFjQX0nx02SCb+h/mrgiFwPNtafgbjAM9sDo3xIAIHSXmRuUlauZa1CmKfyF9ggyHoN/WXAKGxrRsVtSRdFqvfk0F9RE67+V9cA3QY+r+qd8d8USkbspgLlSWonPk2fxbI/HrdQ8Qeti/mBSVi/lklRuip9enPVYZu9uKjsZnEA2Ra7fF0WFZZGMbN5NcBTzT48ylmsBKQoPh5bOIQDBPksvs1wxj/8rWEnIf0wPX7S041yP5KOE5VKEGDDfDp3FU/cHDr9bq3QbtW4P4apwdDeDbYsiRPtggxaHeVVeC125vm5Oc8ksISS+JuBfjoimNtLpJB0ckgRo2KJ6zZYlvgmu6p5htRQUamAc7j0yD99ffzgmC2RIMzuBHEXeQAhkVrPdYcZWbn7QByDRVq4X+eRuxbO4M+TDAue0b7hvHYHL/jRBb X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-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7/FM6OyOuehS9NWiGT9cOsBjFDUGSC5WLzYtumluu/H4g3YkjrIMI56LPv1LJWQYl0Dh/T709YrrBp5SKgYcCSgKooZKcdq6DM0s83SRCUzn01Et1e5tq7DWkWyE2YMsFDWs7x0jYe0vtgt2v6FDihvaZAnncU0l0swsSpIxxnhDVZBTcDgVwKwMBQjO+UuugB+ye/Cyqot4LICXNBQKY+6yjogFmCwIu4i/KsvKJaTl/s+pAwjTQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 84af8fde-b71b-4ba1-24bd-08dc302ad684 X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Feb 2024 02:39:33.2124 (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: AS8P250MB0054 Subject: [FFmpeg-devel] [PATCH 1/5] avcodec/bsf/(hevc|vvc)_mp4toannexb: Ensure extradata_size < INT_MAX 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: kPqN7UPmo2As AVCodecParameters.extradata_size is an int. Signed-off-by: Andreas Rheinhardt --- libavcodec/bsf/hevc_mp4toannexb.c | 2 +- libavcodec/bsf/vvc_mp4toannexb.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libavcodec/bsf/hevc_mp4toannexb.c b/libavcodec/bsf/hevc_mp4toannexb.c index 8eec18f31e..c0df2b79a6 100644 --- a/libavcodec/bsf/hevc_mp4toannexb.c +++ b/libavcodec/bsf/hevc_mp4toannexb.c @@ -69,7 +69,7 @@ static int hevc_extradata_to_annexb(AVBSFContext *ctx) if (!nalu_len || nalu_len > bytestream2_get_bytes_left(&gb) || - 4 + AV_INPUT_BUFFER_PADDING_SIZE + nalu_len > SIZE_MAX - new_extradata_size) { + 4 + nalu_len > FFMIN(INT_MAX, SIZE_MAX) - AV_INPUT_BUFFER_PADDING_SIZE - new_extradata_size) { ret = AVERROR_INVALIDDATA; goto fail; } diff --git a/libavcodec/bsf/vvc_mp4toannexb.c b/libavcodec/bsf/vvc_mp4toannexb.c index 36bdae8f49..1b851f3223 100644 --- a/libavcodec/bsf/vvc_mp4toannexb.c +++ b/libavcodec/bsf/vvc_mp4toannexb.c @@ -159,7 +159,7 @@ static int vvc_extradata_to_annexb(AVBSFContext *ctx) if (!nalu_len || nalu_len > bytestream2_get_bytes_left(&gb) || - 4 + AV_INPUT_BUFFER_PADDING_SIZE + nalu_len > SIZE_MAX - new_extradata_size) { + 4 + nalu_len > FFMIN(INT_MAX, SIZE_MAX) - AV_INPUT_BUFFER_PADDING_SIZE - new_extradata_size) { ret = AVERROR_INVALIDDATA; goto fail; } From patchwork Sun Feb 18 02:44:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 46335 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:dda5:b0:19e:cdac:8cce with SMTP id kw37csp573499pzb; Sat, 17 Feb 2024 18:42:50 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVqQqLDIeG7Td1YqJ6/kvZ4enufzv4NuwCwVCnkSwgerdoxGehfx6pkh/9JBq7dL4nt/zjzGy3W6Z1ySzKAEWFJMi/xChxE7M4jDQ== X-Google-Smtp-Source: AGHT+IFh7T6N9cBaqSVvnKeIW24bfBhPKKrxU4AFHO14zqcQHtqkY1Y60YWDje74+oMUI48MDiYL X-Received: by 2002:a17:906:2456:b0:a3c:c29d:924f with SMTP id a22-20020a170906245600b00a3cc29d924fmr6607236ejb.71.1708224169910; Sat, 17 Feb 2024 18:42:49 -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 lx20-20020a170906af1400b00a3e41c68032si612993ejb.788.2024.02.17.18.42.49; Sat, 17 Feb 2024 18:42:49 -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=dpnusvW3; 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 1330268D20F; Sun, 18 Feb 2024 04:42:47 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05olkn2075.outbound.protection.outlook.com [40.92.89.75]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id ACBC168D1C0 for ; Sun, 18 Feb 2024 04:42:39 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ihSgtesDE54HYK6C7DKGd0sDSfOO7ZhYXr0AcD3nvndRo9DOo1H9RdhWEe+dj3n4QSfTmtqsClbn4A2lZ8ugV4X4GQa2PQQFaIiBLiRJH+9ObltpeWFcNvaE/FReZCA1N/aBZJupNXKeD9nU5M6J76LVXdsmfgI589aPtWMGQ6CSvxLwvZNE+SsdaZDdFjcs84ODwWWQFJ6ODeO/13BwK+oFJmXokwsZFRORjxF0S6eLsIh5gey5xDi96W8OFk90KWt0u4tP1SOYNVUYkf/Oi07xWOFt1WuInfKedGDkhCFfCZNDyakoXfDhnlez7l81IxwbFf939X4o7i+Q/wCKLQ== 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=KsouwisGM3iuQnokY2lRcKIv0FUQ18GJEOHza6pLG/s=; b=VzQ+AV8rIKMzwcyKNFlSmATsAW+LPK/GSfAmRURsSCwA6lLsYVGQ+Xoa4SEnxICV7IaynYRDk9nPdKcLxWjbMP8Xx+FAf8gFb5TO81zC3fcDuBEP70d2EnN3zmlTh2oNO+caTtljUknYHbvR84Jm6mZ1E8BGtA1NVN0FD8o7meUG9KAkt9QuaSi2jV6DGYDzl+KImSl64E4usEwMU7FSJbpnSwxtS/2AKrGTjfAvw1cYxV30q/qtwAoUSP/YLgixuwMZaqRIeIyLjyKETGM7wFLOrHiY2tiyT1nteRhxgYVLsKYBuU6xxq0BGrWNFrIxPO+GCL3sDkJdu8PJ0bfWfw== 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=KsouwisGM3iuQnokY2lRcKIv0FUQ18GJEOHza6pLG/s=; b=dpnusvW36al6jehSxsyauKzwmL7ZRPdM136HEXwrUjn/uHXocWVxofmi18+uWqqtXiTktJe/oM37U7ij2Qx2J5f/BP7In1uft6k1m7bQD8+y/pYt562ougDfiOaNBv23/NSXujyprPYAFWb0xIVVhcHCENtAP7zmcjohQlzrA15GuEMiPNS6nahutLOG/s50Po3DX1YIvohjk/QdknYp3JLI4Jj8I/dJznHBvsBQ3/3hGlIhLvtTzO7p9rlB9JQsfemFj2UbNRaA584fktb/4xUoAkREFrQq/uLP0Hl0BPd8OwxAYQjs8i330MSoO8HmqetEzwoXmaaKbGbCxbIZKQ== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by AS8P250MB0054.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:359::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.32; Sun, 18 Feb 2024 02:42:38 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::65aa:deb0:a18e:d48d]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::65aa:deb0:a18e:d48d%5]) with mapi id 15.20.7292.033; Sun, 18 Feb 2024 02:42:38 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 18 Feb 2024 03:44:24 +0100 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [UdJv6+2Wqw3YXhUc+/X4bGQZ5CM9gBmhgR/ajIg8pgw=] X-ClientProxiedBy: ZR2P278CA0034.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:47::15) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20240218024427.3103449-1-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|AS8P250MB0054:EE_ X-MS-Office365-Filtering-Correlation-Id: 6cbc292b-1be4-41ff-75ec-08dc302b44e6 X-Microso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B2EAwKZ6+sjjNDIXn0zAQvMB181WDvXzX5RLYSYv92f8Lx7usk9GIffkSU67A/vaC2KwzFrecw/L5UIpeVWfcnGxsnEtwrYr+jUTlouzXyJGWdf0I4HSjdg/Bo0cuRbAQb4OD7M8TtCy2nWAkHQ3XzWsp3Mx1qx9GGIQ/VgETYMZ1V0I7JasicE6QwIOz3kiKqKXAW4jmq7ULsrXm2ekepV/yfOgp0y89IKRbaTWPGEGRROuyt4sMPdv4cR2idcZfONZXRXNr9gsELLo2XWVI9neQEiBOBfrpPLFEbzNP6VR7O1++tGZY+36UV+8tbjyFrTajESCWYNJB+D/FF0HWkR/h+tO18sao6y9B/386UtI5/GzO+T9ZJXxL3g5/qLcJ6y4bca9GnSXCkk4l8HIwXve3pAGMo3MdP+4l4C5QmBYyo9SDEHanm/2w76rCW3NVTmhzKkyMdIUYU5b9DxysGgktYX0jGVa4EvRbyc89YIcBKcOUCXztUBPFhkqFwB4sJxyTPrZuryiahm2td3t3EfbUTOIeJexxG82TbOBjYumGT+t3cVUj/J3rLksH1KGDc9tjV9yjfZVxhi+RWKurEVpXh7+rfUZmri9wLlI4W9PUqee2+onBWFGFwPC9YScgNJ0/pSkMxNYh3QG30yWJw7iGvwQFB7Sgj8ij4JgtX06cSth6H5bMC8y+9qpGvRrUICsYkmTY+NtH83SFlqlJatCIEXwRZib4VDoA+oP2XyZ3h/OTSg7O4AzjGY24j1EaoSvP2f8MmqTlFB3XZ3DoTZM+29Rb5SUtg++jZgXUrxManHZPhQixBaUqQp61DvoKlCNcYP8xtiPPhnFS6vol3pn+7dUF5vziriBNcehBp0xVQkFxoZ1m47ZT18kyNFZyG1JGdA6Jp/M2BWWxVvsVLTIojQOJUvjngjOajvZ0UDoI3REBRhqlJrQ7pxGPlUdSnQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 6cbc292b-1be4-41ff-75ec-08dc302b44e6 X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Feb 2024 02:42:37.9446 (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: AS8P250MB0054 Subject: [FFmpeg-devel] [PATCH 2/5] avcodec/bsf/hevc_mp4toannexb: Factor creating new extradata out 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: DWIyGhAGXwMp This is in preparation for the next commit. Signed-off-by: Andreas Rheinhardt --- libavcodec/bsf/hevc_mp4toannexb.c | 64 ++++++++++++++++++++----------- 1 file changed, 41 insertions(+), 23 deletions(-) diff --git a/libavcodec/bsf/hevc_mp4toannexb.c b/libavcodec/bsf/hevc_mp4toannexb.c index c0df2b79a6..a695cba370 100644 --- a/libavcodec/bsf/hevc_mp4toannexb.c +++ b/libavcodec/bsf/hevc_mp4toannexb.c @@ -37,38 +37,32 @@ typedef struct HEVCBSFContext { int extradata_parsed; } HEVCBSFContext; -static int hevc_extradata_to_annexb(AVBSFContext *ctx) +static int hevc_extradata_to_annexb_internal(void *logctx, GetByteContext *gb, + uint8_t **new_extradatap, + size_t *new_extradata_sizep) { - GetByteContext gb; - int length_size, num_arrays, i, j; - int ret = 0; - + int num_arrays = bytestream2_get_byte(gb); uint8_t *new_extradata = NULL; - size_t new_extradata_size = 0; - - bytestream2_init(&gb, ctx->par_in->extradata, ctx->par_in->extradata_size); - - bytestream2_skip(&gb, 21); - length_size = (bytestream2_get_byte(&gb) & 3) + 1; - num_arrays = bytestream2_get_byte(&gb); + size_t new_extradata_size = 0; + int ret; - for (i = 0; i < num_arrays; i++) { - int type = bytestream2_get_byte(&gb) & 0x3f; - int cnt = bytestream2_get_be16(&gb); + for (int i = 0; i < num_arrays; i++) { + int type = bytestream2_get_byte(gb) & 0x3f; + int cnt = bytestream2_get_be16(gb); if (!(type == HEVC_NAL_VPS || type == HEVC_NAL_SPS || type == HEVC_NAL_PPS || type == HEVC_NAL_SEI_PREFIX || type == HEVC_NAL_SEI_SUFFIX)) { - av_log(ctx, AV_LOG_ERROR, "Invalid NAL unit type in extradata: %d\n", + av_log(logctx, AV_LOG_ERROR, "Invalid NAL unit type in extradata: %d\n", type); ret = AVERROR_INVALIDDATA; goto fail; } - for (j = 0; j < cnt; j++) { - const int nalu_len = bytestream2_get_be16(&gb); + for (int j = 0; j < cnt; j++) { + const int nalu_len = bytestream2_get_be16(gb); if (!nalu_len || - nalu_len > bytestream2_get_bytes_left(&gb) || + nalu_len > bytestream2_get_bytes_left(gb) || 4 + nalu_len > FFMIN(INT_MAX, SIZE_MAX) - AV_INPUT_BUFFER_PADDING_SIZE - new_extradata_size) { ret = AVERROR_INVALIDDATA; goto fail; @@ -78,11 +72,38 @@ static int hevc_extradata_to_annexb(AVBSFContext *ctx) goto fail; AV_WB32(new_extradata + new_extradata_size, 1); // add the startcode - bytestream2_get_buffer(&gb, new_extradata + new_extradata_size + 4, nalu_len); + bytestream2_get_buffer(gb, new_extradata + new_extradata_size + 4, nalu_len); new_extradata_size += 4 + nalu_len; memset(new_extradata + new_extradata_size, 0, AV_INPUT_BUFFER_PADDING_SIZE); } } + *new_extradatap = new_extradata; + *new_extradata_sizep = new_extradata_size; + + return 0; +fail: + av_freep(&new_extradata); + return ret; +} + +static int hevc_extradata_to_annexb(AVBSFContext *ctx) +{ + GetByteContext gb; + int length_size; + int ret = 0; + + uint8_t *new_extradata = NULL; + size_t new_extradata_size; + + bytestream2_init(&gb, ctx->par_in->extradata, ctx->par_in->extradata_size); + + bytestream2_skip(&gb, 21); + length_size = (bytestream2_get_byte(&gb) & 3) + 1; + + ret = hevc_extradata_to_annexb_internal(ctx, &gb, &new_extradata, + &new_extradata_size); + if (ret < 0) + return ret; av_freep(&ctx->par_out->extradata); ctx->par_out->extradata = new_extradata; @@ -92,9 +113,6 @@ static int hevc_extradata_to_annexb(AVBSFContext *ctx) av_log(ctx, AV_LOG_WARNING, "No parameter sets in the extradata\n"); return length_size; -fail: - av_freep(&new_extradata); - return ret; } static int hevc_mp4toannexb_init(AVBSFContext *ctx) From patchwork Sun Feb 18 02:44:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 46336 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:dda5:b0:19e:cdac:8cce with SMTP id kw37csp573523pzb; Sat, 17 Feb 2024 18:42:57 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCXp8pfX14fCnO1+KqjhDng/JsCP8TzxeEFJp3QrlBUXpkIYuARhXjIRVcgNpJ6fym6C5sapB7NdccLs0DuKhQW2lKyFyRbhSD37mQ== X-Google-Smtp-Source: AGHT+IFK8uEG+0/TIFdhg1W0/gIgQWhUxpXuTTTTKpqQb+xiLe4BespEoKwt3waQFiL6kgRu5/E3 X-Received: by 2002:a17:906:6c90:b0:a3e:ba1:76f9 with SMTP id s16-20020a1709066c9000b00a3e0ba176f9mr2054182ejr.63.1708224177183; Sat, 17 Feb 2024 18:42:57 -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 w17-20020a170906131100b00a3e64395af4si247054ejb.857.2024.02.17.18.42.56; Sat, 17 Feb 2024 18:42:57 -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=AVXSWtIE; 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 4C9E668D326; Sun, 18 Feb 2024 04:42:51 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05olkn2075.outbound.protection.outlook.com [40.92.89.75]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id DB45D68D314 for ; Sun, 18 Feb 2024 04:42:44 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IJBY25G7MA8KUVnEHeTMYuKPGbXrKjeVed/g9U/cIWAicS7xfmi6EUcOVz7dSYe7u9RVfEWj4nB6Y6epSoxJIHh4h0bbGhqBMzcjg9GCCb0lfFIQy1nrA6QsyjOgvJgXiGrbCcj6TxDDPajJ1/iAhtrk2x8Pe6b6J/bMzZsRTRF9FeDTOvppRaHCL1IYDS46JhADcyEXdYWvjfiE0oVmOqrXkQeisJGCqI+yNkxGgl/kAEJO3mS6idPYhxm02Mxqd7CDxqkd18j14bN+T93o4MfZvt7Z5I6G5rCcgMbqAtkNrX6b4jLf2lTmy2L0/zPtmHJHYALQxwyqIUXRBJswUg== 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=8yafLX/6PQ68V6tCQrkuuznnlEljL7dKXiBCxsMm5F0=; b=Mcb5XnhF2IA/g57A0frKI3I21yRMaLxVRaYVVOqO13KipGyhmMEh4t8D+zn6oN8VmMFiiuQRUYjmf/G9TJfb4Z3EK/+b/DxK60K7FUSEE0J+cUY7XUxWVLHdRoadM8F4c/DH5Up78AXK4oG/a9pwlAj9+w7gIlQ3OXftQe2NE3eSkcnzRFMJYjJ5uq2ekarTZUpjG12jBrOyaVUQiwRllcKl1XmwIypZM9dYWJL9msG3gHA49oe3hGB/RYX12Ix7yQeglms2ZHbybhXxMMLApZRM3kNYdMMPbFXgb3kMTQRHlv3wZsLbDvrbOaDzSnJfi79kO2Fr7Ne5RSfoN57V2Q== 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=8yafLX/6PQ68V6tCQrkuuznnlEljL7dKXiBCxsMm5F0=; b=AVXSWtIExZRG0RotN+fpr6Ccf/jGreVYq6JWYA3B2mXg90sf2476mhpL3vYQaA2LPJo3eGC/G32XSliCgKIro7q+h03RG4d0/eY7Wcmwl1AGJSEjMcqgg5oWAbl1ShSYb4g0+bRkXp22XzXiSw3kFe92KYPqedocY+73zfh2mzUWqkqMb+PfJ3sP1gtQZRlgAkfGlkeUPBRwDVBQULiNhNmaIg2JphZo0Hf39B1CQ2xoQoIkZGPraUSBNOEZbUsl12Bd5yo92FDE08hBAlYctAluHn9Za3d0DC9qx4ghFhsbBc47dFHA3EAOnaiG03okHJs2DJG6L03elzcTqrWC4g== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by AS8P250MB0054.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:359::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.32; Sun, 18 Feb 2024 02:42:41 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::65aa:deb0:a18e:d48d]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::65aa:deb0:a18e:d48d%5]) with mapi id 15.20.7292.033; Sun, 18 Feb 2024 02:42:41 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 18 Feb 2024 03:44:25 +0100 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [iqEIoBSvtHgPAVgxcIJTZWDy36KwfoKNgJaaJg6DSyA=] X-ClientProxiedBy: ZR2P278CA0034.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:47::15) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20240218024427.3103449-2-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|AS8P250MB0054:EE_ X-MS-Office365-Filtering-Correlation-Id: 937d6548-6c64-4477-c22e-08dc302b46d6 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UnRfjd79zx9C5IGHPOyCcArh9zXTHzEC08KzLK/ToxFETQHEezyEzLwvmxzQh8zzkXNOl2uTtrB9+RPfE22BRYkU1i4TeEVD4Ev8qYVOCjmDCwK13WEPqUDDIkwyUJwyw1nr0N5o5rgXE9gC2ULrDNglCAn34v+oXX0tFkn7EMQA6ZSoNDhsr3nrSiZJNhX2vIBFuRZVRp6ttlJ+83rO41G4S5Ca5Io/K4Q+8MTSLiYcLKalQXcqiyhT6Q8evXJNnNcMydi75Naws3VxThIgHvEjUUm/PTI2cYhoJcqEVKH9Ui26UyzSRx0y6iNz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a49apYjaYaoABYPBm+68+N/baQCBq7AnfrRW2app9Qx9HonMqtILUZr8UPhedMGp1z+oDlfJvNRMqUEc2dAkbnQ6RLnXfNCaIZvrk51/zaAVBfmMji9Nm68h1QAkCiIbshSqcVXfnByCj4TRBF6l/aR33SgoJg6ShnkZBm82oASyL9c7QK670p1EZugoYUC76go+9NcdDIcvXpglqImhoMyjAR0Un6GKvSpI6VaLiW3P7i44gj9R8H/U5fgkFHauVknj3//ZDj2PsEUuWyfKAqR/ZMyZL/bvE682PhtsB/Mhe4vnsELsIQk09rvwG3oMK9HRRDmkBRSGg0LrArRR0gWryxmIF94o3O61x2I2IzqUulMEQQxjXr7JAx5ch279KbjSmgMZQomTuuw3PYsgx8pmj0Gkra7LJTRxMBE51xVM65dbFEA3typjsTgW7KL5Xe5+NUopBHipjgh90zo35sVqT6XodYJG4drm+inoD43EQkwd/l9EmfIgQEoHwPwi2hAZ9saarDK61TV0E2FoPL8icqdY0DRXV4a/u8VKmFdsmC9pLIUrI9whO2DYi/+wNFQYxhO7mQ49PgEmf5mNMr4By24cO9/5yRRA== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 937d6548-6c64-4477-c22e-08dc302b46d6 X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Feb 2024 02:42:41.1774 (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: AS8P250MB0054 Subject: [FFmpeg-devel] [PATCH 3/5] avcodec/bsf/hevc_mp4toannexb: Don't realloc when creating new extradata 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: zFWCjXwRHhnm AVCodecParameters.extradata is supposed to be allocated with av_malloc(); av_realloc() and its wrappers do not guarantee the proper alignment. Therefore parse the extradata twice: Once to check its validity and to determine the eventual size and a second time to actually write the new extradata. (Of course, not reallocating the buffer is beneficial in itself.) Signed-off-by: Andreas Rheinhardt --- libavcodec/bsf/hevc_mp4toannexb.c | 44 +++++++++++++++---------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/libavcodec/bsf/hevc_mp4toannexb.c b/libavcodec/bsf/hevc_mp4toannexb.c index a695cba370..f5424e95b8 100644 --- a/libavcodec/bsf/hevc_mp4toannexb.c +++ b/libavcodec/bsf/hevc_mp4toannexb.c @@ -38,13 +38,11 @@ typedef struct HEVCBSFContext { } HEVCBSFContext; static int hevc_extradata_to_annexb_internal(void *logctx, GetByteContext *gb, - uint8_t **new_extradatap, + uint8_t *new_extradata, size_t *new_extradata_sizep) { int num_arrays = bytestream2_get_byte(gb); - uint8_t *new_extradata = NULL; size_t new_extradata_size = 0; - int ret; for (int i = 0; i < num_arrays; i++) { int type = bytestream2_get_byte(gb) & 0x3f; @@ -54,8 +52,7 @@ static int hevc_extradata_to_annexb_internal(void *logctx, GetByteContext *gb, type == HEVC_NAL_SEI_PREFIX || type == HEVC_NAL_SEI_SUFFIX)) { av_log(logctx, AV_LOG_ERROR, "Invalid NAL unit type in extradata: %d\n", type); - ret = AVERROR_INVALIDDATA; - goto fail; + return AVERROR_INVALIDDATA; } for (int j = 0; j < cnt; j++) { @@ -64,26 +61,19 @@ static int hevc_extradata_to_annexb_internal(void *logctx, GetByteContext *gb, if (!nalu_len || nalu_len > bytestream2_get_bytes_left(gb) || 4 + nalu_len > FFMIN(INT_MAX, SIZE_MAX) - AV_INPUT_BUFFER_PADDING_SIZE - new_extradata_size) { - ret = AVERROR_INVALIDDATA; - goto fail; + return AVERROR_INVALIDDATA; } - ret = av_reallocp(&new_extradata, new_extradata_size + nalu_len + 4 + AV_INPUT_BUFFER_PADDING_SIZE); - if (ret < 0) - goto fail; - - AV_WB32(new_extradata + new_extradata_size, 1); // add the startcode - bytestream2_get_buffer(gb, new_extradata + new_extradata_size + 4, nalu_len); + if (new_extradata) { + AV_WB32(new_extradata + new_extradata_size, 1); // add the startcode + bytestream2_get_bufferu(gb, new_extradata + new_extradata_size + 4, nalu_len); + } else + bytestream2_skipu(gb, nalu_len); new_extradata_size += 4 + nalu_len; - memset(new_extradata + new_extradata_size, 0, AV_INPUT_BUFFER_PADDING_SIZE); } } - *new_extradatap = new_extradata; *new_extradata_sizep = new_extradata_size; return 0; -fail: - av_freep(&new_extradata); - return ret; } static int hevc_extradata_to_annexb(AVBSFContext *ctx) @@ -100,10 +90,20 @@ static int hevc_extradata_to_annexb(AVBSFContext *ctx) bytestream2_skip(&gb, 21); length_size = (bytestream2_get_byte(&gb) & 3) + 1; - ret = hevc_extradata_to_annexb_internal(ctx, &gb, &new_extradata, - &new_extradata_size); - if (ret < 0) - return ret; + while (1) { + GetByteContext gb_bak = gb; + ret = hevc_extradata_to_annexb_internal(ctx, &gb, new_extradata, + &new_extradata_size); + if (ret < 0) + return ret; + if (new_extradata || !new_extradata_size) + break; + new_extradata = av_malloc(new_extradata_size + AV_INPUT_BUFFER_PADDING_SIZE); + if (!new_extradata) + return AVERROR(ENOMEM); + memset(new_extradata + new_extradata_size, 0, AV_INPUT_BUFFER_PADDING_SIZE); + gb = gb_bak; + } av_freep(&ctx->par_out->extradata); ctx->par_out->extradata = new_extradata; From patchwork Sun Feb 18 02:44:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 46337 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:dda5:b0:19e:cdac:8cce with SMTP id kw37csp573546pzb; Sat, 17 Feb 2024 18:43:05 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWVvhKYSPLy7OAMfif/WZETTxuGY4AFEZRt1pjCkpq3v0geOT2OusQFeXdTwHBJeHlB46jRW9xK5yoGql5Af+4SYGD/7MQwt99+hQ== X-Google-Smtp-Source: AGHT+IHgF7dtPCxRXdY/SCe4t2q047AZHeU8I28vUs3/YjiXp0IE009W4MKaEkTunuWYE9RyCavJ X-Received: by 2002:a05:6402:545:b0:564:4211:6705 with SMTP id i5-20020a056402054500b0056442116705mr728452edx.10.1708224184972; Sat, 17 Feb 2024 18:43:04 -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 w3-20020a50d783000000b005645a23c239si147769edi.585.2024.02.17.18.43.04; Sat, 17 Feb 2024 18:43:04 -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=CkB5fZBr; 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 7FBA768D331; Sun, 18 Feb 2024 04:42:56 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05olkn2075.outbound.protection.outlook.com [40.92.89.75]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 0C6D168D2EB for ; Sun, 18 Feb 2024 04:42:50 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=K1+DNuQ6ifqqesX7QSUDXFqTurb/JgKmO8LZUYADCvXXdlm6QtbjxhgB7NDs+J4ZAEIepLNZ3XpNg7J5jt1YEexX1Lm22HT9zmSgVinnzKBX9SYkdH+e3/aNyMivSZK+8WOEFVCb8fkuWyOaStgJErpGR7FbdOHtYINJD2M6yJeoZEkskjvZ1jR+Ura+3TYOmWISgN7TBzUbHPttiOD0JzWpKpqMGZb2z512qcnZb4OIPFPrTYB0MQJRX1zw9lxsZedfPE9uYo7aNU2IQl46KOG61jU8eJMMl2WYGHapRJBk4+/BNWSAEYdiJfp4HDmOsQ6U4HLE7hFtfZizhnQ39g== 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=hPfxS/oGG4EziHAO43GK0H2EAE9yYmBFB5nFS9mMkso=; b=Gx4NFjY54k26XjYvAl81+T1F89RmI0HHuUJmL4XZXk/9NC5fHqSU7QbnInZS7ey8QQowlXT2+GfeyMbFh09M4gKoF/HibgTfUtbqDvugH0C2wAFPB34rgYP1DkQ+9ufuVF7Qzp6KSBzbTtn50C3Fe0qzy6TTwxH09T8spXfzINLg974WmwfriIVdYz9KmOlr/GQ6rrLoB6v5yAdnRxCQhVJ2Q4vnJG0L1inLTkSsHscQgg5J7AaEEoDCfpCD8zDlfDZLsxnTX8cbYOBD0idyETY4JkDsk8Pk11Vz0LL+ogC5Jg2EWO/Ovxgl4ZBhmq2mlBE2jS9K/Dq3H4SBKIbTvg== 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=hPfxS/oGG4EziHAO43GK0H2EAE9yYmBFB5nFS9mMkso=; b=CkB5fZBrFqYXn+l9scuhaJzOLWP2JSMwvHt5/yNXQc4hROMQjq6na2mR+fb7iVg1w2YDjeJCj9XY6pfF2GfSHDB7dSWSbiYgYVt9cM7rFP+p6v7mgvuOcdL68gOPvEhItJWRGRqkKKNyUUp7MXbOW+rm6ExJZkrfbsTroP4Bq7sWSMiE8qoevrwAI8B4z96ucSm+MxiUkq07AJPBS4f6wD8gxFka8Wp5aXIHHrGN6AvlJ3RmCX7ZbecglvapirxbsL9csdo4ahrA9WhFyhph3fNCdB9zJjs+lkuokj4JxbNFaEWLWGy4Kx6/kS7H+XL6+pVlqLc4/8xCd2t5BhnOgQ== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by AS8P250MB0054.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:359::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.32; Sun, 18 Feb 2024 02:42:43 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::65aa:deb0:a18e:d48d]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::65aa:deb0:a18e:d48d%5]) with mapi id 15.20.7292.033; Sun, 18 Feb 2024 02:42:43 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 18 Feb 2024 03:44:26 +0100 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [EawqAkI1zlgQjD5lWCUYoGBQeq+CP2Gfn/GOXwswL3s=] X-ClientProxiedBy: ZR2P278CA0034.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:47::15) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20240218024427.3103449-3-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|AS8P250MB0054:EE_ X-MS-Office365-Filtering-Correlation-Id: f17d8b4a-a07f-4940-5bd4-08dc302b486e X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KYFwjXkOrlnAQnfyZnoVdMkRMyvdxmNWfwmfRzlhfCLRbT0G72VkK+5jqvQdK49OfEomE9/X3alv9gyldM351BxgHATYuzEtF2lLfQKiJ+BeveLQZAxIoHOO8f7t/A/VED7l/dTOi9SUUEHMdLQwnw7cgaRsoftOHRtRtukK3E+a37B4VlFwNkVp+GkGDuVTa7oGaRezMPdh4a9P+uec2tuiBSBSaWMQg2uRMidUEFN1BafdlyZCNOrl1O9j49BVWENb8UxbwPIie37OHyoOODZOIEPFqKRBl2J6TUVh3BP4gJ+dttGGdMskF6hJyXdj9MhEwOAeNs/kylg6JMJ6s6SPQu3dxn+I2smoDQ+NeIDfLnalGO0wc/imR+qbEuKylJV9Lm+OMJ0Z10+ZjL174JgdX1hOEVkeCZ2Z7IO+BTbqu29bDNraVVTUJ3YQzrodcWgrcl2gt6cq7PHvGh+H7qF0m3l69OK25oNoO5KBLLg5El8r8BAVcd7R3E0hHZF4QSNXzzEienYQRJAuEDlbyqiHwE8enkCCxSHBa3qIvRvs24WOVhBCrdHRNdc3ShXhDCbHRwou+NsMo2QUCm8KcD90wBZ3puHon+EivrCE3s+JkwxQ8n4CMHIHYcJVLZcG X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 0w4PtOYudfW2T+HTCPfkJscEDVFG5TdHx/CAnOA43S1T4IdW5MWKyIXxDMteOpfyAtjAzbQiDgH/NbNvV6A8cdPO9CYPRmgZ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yZznUfeV+DcKImClE61QZyc2YdLuPMWQD5o0uliuKo3cksjsLMSURuIIviDnIPyb+KkgI4FpjUU4P5fU4sq7mVXE8yyCfvkNg+vuFKByr/v1gGCIlhEVl2AQ== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: f17d8b4a-a07f-4940-5bd4-08dc302b486e X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Feb 2024 02:42:43.8246 (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: AS8P250MB0054 Subject: [FFmpeg-devel] [PATCH 4/5] avcodec/bsf/vvc_mp4toannexb: Factor creating new extradata out 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: dDubNzbOJC7v This is in preparation for the next commit. Signed-off-by: Andreas Rheinhardt --- libavcodec/bsf/vvc_mp4toannexb.c | 116 ++++++++++++++++++------------- 1 file changed, 67 insertions(+), 49 deletions(-) diff --git a/libavcodec/bsf/vvc_mp4toannexb.c b/libavcodec/bsf/vvc_mp4toannexb.c index 1b851f3223..bfb0338116 100644 --- a/libavcodec/bsf/vvc_mp4toannexb.c +++ b/libavcodec/bsf/vvc_mp4toannexb.c @@ -37,16 +37,77 @@ typedef struct VVCBSFContext { int extradata_parsed; } VVCBSFContext; +static int vvc_extradata_to_annexb_internal(void *logctx, GetByteContext *gb, + uint8_t **new_extradatap, + size_t *new_extradata_sizep) +{ + int num_arrays = bytestream2_get_byte(gb); + uint8_t *new_extradata = NULL; + size_t new_extradata_size = 0; + int ret; + + for (int i = 0; i < num_arrays; i++) { + int cnt; + int type = bytestream2_get_byte(gb) & 0x1f; + + if (type == VVC_OPI_NUT || type == VVC_DCI_NUT) + cnt = 1; + else + cnt = bytestream2_get_be16(gb); + + av_log(logctx, AV_LOG_DEBUG, "nalu_type %d cnt %d\n", type, cnt); + + if (!(type == VVC_OPI_NUT || type == VVC_DCI_NUT || + type == VVC_VPS_NUT || type == VVC_SPS_NUT || type == VVC_PPS_NUT + || type == VVC_PREFIX_SEI_NUT || type == VVC_SUFFIX_SEI_NUT)) { + av_log(logctx, AV_LOG_ERROR, + "Invalid NAL unit type in extradata: %d\n", type); + ret = AVERROR_INVALIDDATA; + goto fail; + } + + for (int j = 0; j < cnt; j++) { + const int nalu_len = bytestream2_get_be16(gb); + + if (!nalu_len || + nalu_len > bytestream2_get_bytes_left(gb) || + 4 + nalu_len > FFMIN(INT_MAX, SIZE_MAX) - AV_INPUT_BUFFER_PADDING_SIZE - new_extradata_size) { + ret = AVERROR_INVALIDDATA; + goto fail; + } + ret = av_reallocp(&new_extradata, new_extradata_size + nalu_len + 4 + + AV_INPUT_BUFFER_PADDING_SIZE); + if (ret < 0) + goto fail; + + AV_WB32(new_extradata + new_extradata_size, 1); // add the startcode + bytestream2_get_buffer(gb, new_extradata + new_extradata_size + 4, + nalu_len); + new_extradata_size += 4 + nalu_len; + memset(new_extradata + new_extradata_size, 0, + AV_INPUT_BUFFER_PADDING_SIZE); + } + } + + *new_extradatap = new_extradata; + *new_extradata_sizep = new_extradata_size; + + return 0; +fail: + av_freep(&new_extradata); + return ret; +} + static int vvc_extradata_to_annexb(AVBSFContext *ctx) { GetByteContext gb; - int length_size, num_arrays, i, j; + int length_size, i, j; int ret = 0; int temp = 0; int ptl_present; uint8_t *new_extradata = NULL; - size_t new_extradata_size = 0; + size_t new_extradata_size; int max_picture_width = 0; int max_picture_height = 0; @@ -132,50 +193,10 @@ static int vvc_extradata_to_annexb(AVBSFContext *ctx) max_picture_width, max_picture_height, avg_frame_rate); } - num_arrays = bytestream2_get_byte(&gb); - - for (i = 0; i < num_arrays; i++) { - int cnt; - int type = bytestream2_get_byte(&gb) & 0x1f; - - if (type == VVC_OPI_NUT || type == VVC_DCI_NUT) - cnt = 1; - else - cnt = bytestream2_get_be16(&gb); - - av_log(ctx, AV_LOG_DEBUG, "nalu_type %d cnt %d\n", type, cnt); - - if (!(type == VVC_OPI_NUT || type == VVC_DCI_NUT || - type == VVC_VPS_NUT || type == VVC_SPS_NUT || type == VVC_PPS_NUT - || type == VVC_PREFIX_SEI_NUT || type == VVC_SUFFIX_SEI_NUT)) { - av_log(ctx, AV_LOG_ERROR, - "Invalid NAL unit type in extradata: %d\n", type); - ret = AVERROR_INVALIDDATA; - goto fail; - } - - for (j = 0; j < cnt; j++) { - const int nalu_len = bytestream2_get_be16(&gb); - - if (!nalu_len || - nalu_len > bytestream2_get_bytes_left(&gb) || - 4 + nalu_len > FFMIN(INT_MAX, SIZE_MAX) - AV_INPUT_BUFFER_PADDING_SIZE - new_extradata_size) { - ret = AVERROR_INVALIDDATA; - goto fail; - } - ret = av_reallocp(&new_extradata, new_extradata_size + nalu_len + 4 - + AV_INPUT_BUFFER_PADDING_SIZE); - if (ret < 0) - goto fail; - - AV_WB32(new_extradata + new_extradata_size, 1); // add the startcode - bytestream2_get_buffer(&gb, new_extradata + new_extradata_size + 4, - nalu_len); - new_extradata_size += 4 + nalu_len; - memset(new_extradata + new_extradata_size, 0, - AV_INPUT_BUFFER_PADDING_SIZE); - } - } + ret = vvc_extradata_to_annexb_internal(ctx, &gb, &new_extradata, + &new_extradata_size); + if (ret < 0) + return ret; av_freep(&ctx->par_out->extradata); ctx->par_out->extradata = new_extradata; @@ -185,9 +206,6 @@ static int vvc_extradata_to_annexb(AVBSFContext *ctx) av_log(ctx, AV_LOG_WARNING, "No parameter sets in the extradata\n"); return length_size; - fail: - av_freep(&new_extradata); - return ret; } static int vvc_mp4toannexb_init(AVBSFContext *ctx) From patchwork Sun Feb 18 02:44:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 46338 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:dda5:b0:19e:cdac:8cce with SMTP id kw37csp573576pzb; Sat, 17 Feb 2024 18:43:13 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCVrHRjL+58tVj4inkWAgcI9XFrUUoqv7088xgvS85SzRGapHByQL1VTChw9LEAH8j8rWtoyRqWZz6gE5U+XIdYwzKtPefNkWrrxqQ== X-Google-Smtp-Source: AGHT+IFbeinU/uCbc3odaizgphiQq3VvIpXZOxUb4aWM9vpmXLboXQHTPv3OCLR9g3bnunz1ujMK X-Received: by 2002:a17:906:1397:b0:a3d:2356:c582 with SMTP id f23-20020a170906139700b00a3d2356c582mr6170426ejc.48.1708224193008; Sat, 17 Feb 2024 18:43:13 -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 gy21-20020a170906f25500b00a3e6a56e10bsi182194ejb.485.2024.02.17.18.43.12; Sat, 17 Feb 2024 18:43:12 -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=lrE061rR; 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 A2E3768D330; Sun, 18 Feb 2024 04:43:01 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05olkn2066.outbound.protection.outlook.com [40.92.89.66]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B38A968D322 for ; Sun, 18 Feb 2024 04:43:00 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SynURZnHSORWfdxP9YPibqhQnIqH2q82xw1IA8okMRC3jFF7DrUGv7CoraongRxaK9Bs+GVij0Cw4GhY9YS/DF2hrKRdDspQguiKMSTnpSkM+paimgdUfOrrC5uUfc1pB8EUt8C84nsJDzqs4ogVffdZ3a4ZA/HoEWik5aHuD7tzjt5E/fmRN2DfOf1nkBnN/LXqLPQSL00Zjmk6c9nb1VkJg5NokhDEisA8YLY9OguDJMmheQrg00hSdg6vLy9OcnSxu5MYpnnEE037BPAsdURWY9z8y5lIC4LXOm7I928eNXLRrcbFVEjlVdBJJXs4RBg+UgyHnMed2GbxERDaSw== 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=lnSgkqIQ1BtvY1cWWNnt+5woXT4ntnFx7gIdF2+3+Is=; b=kGaTZWfSORK3Azbyicfflc5a80kxR3e9ijAavzohWtlgZHXtVCb6qah22vs6hjm3JaXaurXyfBW3ADHD0asYcL/gG2HAx1KoqB93ySOutbSAPo5QJo5S8BP6B+bGEJ0uxLPIWhEfMNFkeF3x5dvsrcNj3iwYhcSToedMQXI5oMx7NhqpGabKY/hNoRXRmDI98ZSRVY7Z5ItPYCjAvljYmAvsTZPd1r2dnJy2uEgjRWpCTCoTZ2etIaXc/GMsvof/PqrBVIVlmWc47BE2oVTBVA8AtoZvRnTO2/HioEFLWGjJCrN147yzmmvuzTSsh1CeBEqB0YN6gEVOSI7CI3Bm8g== 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=lnSgkqIQ1BtvY1cWWNnt+5woXT4ntnFx7gIdF2+3+Is=; b=lrE061rRaYUXnm3QHWKNTc1f8JIYdHKeRacShwSoZ4PiW+hUt8bdNL+FZ5QDmpI3azghS/Kn6452kIyzRsLtHZw7RFKLADrj1EXHFhZNYXFt1rEF0VDfXhTu4gfKhytC3Tkd+mhd34iMID2hvVMX6J55+ccuoJEumTk0zkc/FQlGzxNh/UQopQgXXVzZVVpT/7VST/ch4l8v1Yov1oyiVee2P9RaNgNs2FL7a3gG6iAwZa5ZzuRGFFsFFgr7TqIeTrKrto9QsBs011xORkB32nKA7dbMimPsQdLeEE+TbE71OWMcy3EamNLc2ikPmQjAlyrok42gMVF3aRvWtkenjA== Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) by AS8P250MB0054.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:359::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7292.32; Sun, 18 Feb 2024 02:42:59 +0000 Received: from AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::65aa:deb0:a18e:d48d]) by AS8P250MB0744.EURP250.PROD.OUTLOOK.COM ([fe80::65aa:deb0:a18e:d48d%5]) with mapi id 15.20.7292.033; Sun, 18 Feb 2024 02:42:59 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 18 Feb 2024 03:44:27 +0100 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [oLC7BCn7uUiwQdK4hp/t8GvhFNy3xrDJRiGIFDuu614=] X-ClientProxiedBy: ZR2P278CA0034.CHEP278.PROD.OUTLOOK.COM (2603:10a6:910:47::15) To AS8P250MB0744.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:541::14) X-Microsoft-Original-Message-ID: <20240218024427.3103449-4-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8P250MB0744:EE_|AS8P250MB0054:EE_ X-MS-Office365-Filtering-Correlation-Id: 942ba4f0-8659-4e5c-ae69-08dc302b5180 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: UOoFwI/KT2rGX99ChSa/ldkAtH5pQPmVr61db2Z0sODvhWT5Egg/QYhXfx83NnfNqkYIAt9OM0xGRn/NrfGhfXVNnXFyHNPZx/FMxzLjCw2ELuoTmkgqRL+yiFjTk7XXR4FelN/l54MdcJkWU5L8WPBMxPdPHZ2GRpzXV8IsdENcCS8L1fQ10xup1dPSnZOblVq3M5rROuQ9E874QVFHMPrjKVZSyxPDCkKRvyFpdCQoEZdxJjuj7sVriX30p9Ebc7y/lEeMGn7FB+GO9yvBtj5pookomJN+hwrPzvha288c8pEOmihNmFdWs+zENcKMN3nj0lBx+cpwSKK/KPhWB384+1qKQ6+eISENMr16vrkvB4LxqdOizZgXL2gMh7aF+LiZeqP0TgysJhubcDllrwavQMVvDVWeDkDOnODl/G4i3r18IZ8JAtKLknsWfK2569EYdhfDvzrxmAWzEBaRTwP10cUWBFF0+UL/aaWMHF35s7NzB7G0KiO8cY2bEo5J3azJ23PQ2C4k35KGDI3oh50x0MEQiRnS3Bvy3hGxGJglpL8SD4a9VzbdFhyS2ET/PtODAh0ekKPKBjy//rZ5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LArA62G8fprIlP7RkJW45X2riroL4kTKAUW1mo6asM+mOZPMNP78mg8XicHdoZy4xljbfvh1fnz8AY/Hxj4vgIK53uuYDllDLDZNM/k6++DOIr2epFf4Fnqkr12r1l4zVV1QbcYNzx6kFDuNZvcQVgsgngS6YHJ+i/hF1VnCY4GwmbCcAkvQlfz0COJf/ntquchaTgpIvvS95ncJ0gLqA3Ko+YJdrpQCm9NLLqIGZjjpr/OM0xPikiPhypVoxwxzRW5947yfthoKKqbgk70d5jNBRPeiFd5z3fjB4W8NV/eewGQxx0ILGYLVx5Piim/C45HsNdkUZPGYFg== X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: 942ba4f0-8659-4e5c-ae69-08dc302b5180 X-MS-Exchange-CrossTenant-AuthSource: AS8P250MB0744.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Feb 2024 02:42:59.0468 (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: AS8P250MB0054 Subject: [FFmpeg-devel] [PATCH 5/5] avcodec/bsf/vvc_mp4toannexb: Don't realloc when creating new extradata 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: OXw9+XcKKzw7 AVCodecParameters.extradata is supposed to be allocated with av_malloc(); av_realloc() and its wrappers do not guarantee the proper alignment. Therefore parse the extradata twice: Once to check its validity and to determine the eventual size and a second time to actually write the new extradata. (Of course, not reallocating the buffer is beneficial in itself.) Signed-off-by: Andreas Rheinhardt --- libavcodec/bsf/vvc_mp4toannexb.c | 51 ++++++++++++++++---------------- 1 file changed, 25 insertions(+), 26 deletions(-) diff --git a/libavcodec/bsf/vvc_mp4toannexb.c b/libavcodec/bsf/vvc_mp4toannexb.c index bfb0338116..1879c1fab9 100644 --- a/libavcodec/bsf/vvc_mp4toannexb.c +++ b/libavcodec/bsf/vvc_mp4toannexb.c @@ -38,13 +38,11 @@ typedef struct VVCBSFContext { } VVCBSFContext; static int vvc_extradata_to_annexb_internal(void *logctx, GetByteContext *gb, - uint8_t **new_extradatap, + uint8_t *new_extradata, size_t *new_extradata_sizep) { int num_arrays = bytestream2_get_byte(gb); - uint8_t *new_extradata = NULL; size_t new_extradata_size = 0; - int ret; for (int i = 0; i < num_arrays; i++) { int cnt; @@ -55,15 +53,15 @@ static int vvc_extradata_to_annexb_internal(void *logctx, GetByteContext *gb, else cnt = bytestream2_get_be16(gb); - av_log(logctx, AV_LOG_DEBUG, "nalu_type %d cnt %d\n", type, cnt); + if (!new_extradata) + av_log(logctx, AV_LOG_DEBUG, "nalu_type %d cnt %d\n", type, cnt); if (!(type == VVC_OPI_NUT || type == VVC_DCI_NUT || type == VVC_VPS_NUT || type == VVC_SPS_NUT || type == VVC_PPS_NUT || type == VVC_PREFIX_SEI_NUT || type == VVC_SUFFIX_SEI_NUT)) { av_log(logctx, AV_LOG_ERROR, "Invalid NAL unit type in extradata: %d\n", type); - ret = AVERROR_INVALIDDATA; - goto fail; + return AVERROR_INVALIDDATA; } for (int j = 0; j < cnt; j++) { @@ -72,30 +70,21 @@ static int vvc_extradata_to_annexb_internal(void *logctx, GetByteContext *gb, if (!nalu_len || nalu_len > bytestream2_get_bytes_left(gb) || 4 + nalu_len > FFMIN(INT_MAX, SIZE_MAX) - AV_INPUT_BUFFER_PADDING_SIZE - new_extradata_size) { - ret = AVERROR_INVALIDDATA; - goto fail; + return AVERROR_INVALIDDATA; } - ret = av_reallocp(&new_extradata, new_extradata_size + nalu_len + 4 - + AV_INPUT_BUFFER_PADDING_SIZE); - if (ret < 0) - goto fail; - - AV_WB32(new_extradata + new_extradata_size, 1); // add the startcode - bytestream2_get_buffer(gb, new_extradata + new_extradata_size + 4, - nalu_len); + if (new_extradata) { + AV_WB32(new_extradata + new_extradata_size, 1); // add the startcode + bytestream2_get_bufferu(gb, new_extradata + new_extradata_size + 4, + nalu_len); + } else + bytestream2_skipu(gb, nalu_len); new_extradata_size += 4 + nalu_len; - memset(new_extradata + new_extradata_size, 0, - AV_INPUT_BUFFER_PADDING_SIZE); } } - *new_extradatap = new_extradata; *new_extradata_sizep = new_extradata_size; return 0; -fail: - av_freep(&new_extradata); - return ret; } static int vvc_extradata_to_annexb(AVBSFContext *ctx) @@ -193,10 +182,20 @@ static int vvc_extradata_to_annexb(AVBSFContext *ctx) max_picture_width, max_picture_height, avg_frame_rate); } - ret = vvc_extradata_to_annexb_internal(ctx, &gb, &new_extradata, - &new_extradata_size); - if (ret < 0) - return ret; + while (1) { + GetByteContext gb_bak = gb; + ret = vvc_extradata_to_annexb_internal(ctx, &gb, new_extradata, + &new_extradata_size); + if (ret < 0) + return ret; + if (new_extradata || !new_extradata_size) + break; + new_extradata = av_malloc(new_extradata_size + AV_INPUT_BUFFER_PADDING_SIZE); + if (!new_extradata) + return AVERROR(ENOMEM); + memset(new_extradata + new_extradata_size, 0, AV_INPUT_BUFFER_PADDING_SIZE); + gb = gb_bak; + } av_freep(&ctx->par_out->extradata); ctx->par_out->extradata = new_extradata;