From patchwork Wed Sep 28 18:43:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 38451 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1c:b0:96:9ee8:5cfd with SMTP id c28csp436421pzh; Wed, 28 Sep 2022 11:43:21 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4RIx25sHtmbF+pjIueQaxuxPEYquAIEW65Lml5MDUIdABpyIpo1w+vVb8a3f4lgz/z1bcL X-Received: by 2002:a17:907:a40e:b0:783:4d41:a159 with SMTP id sg14-20020a170907a40e00b007834d41a159mr16138812ejc.212.1664390601536; Wed, 28 Sep 2022 11:43:21 -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 v14-20020a17090606ce00b00778995de77csi4657136ejb.605.2022.09.28.11.43.21; Wed, 28 Sep 2022 11:43:21 -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=meJv4P6k; 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 AA8CA68BBFC; Wed, 28 Sep 2022 21:43:15 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-oln040092074087.outbound.protection.outlook.com [40.92.74.87]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7F74168BAE5 for ; Wed, 28 Sep 2022 21:43:09 +0300 (EEST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IvDxc0x+Kr72doECSbfQ3P1YRNGPqPpWWJ/RUYpEK/4SUzMkyIZbHFmj7nRbuBOGrcjDBGVdNRceeT4p5aYkh/Rgoj/S8Polqxh1F0whxyDv5rhgOaw4jEskP+2o3CXrbdFBFhW98CMccgdEKxUGz95wKEfNXoSdoa/3imw05rhYhokzmx34EzWKyZn6HoGQGYRMAGIE8Sahp081SENvqvOBGh8RYHEhh+LFg6NNKqAt83Tox3G8Q96aMOToQejMIS+xxHw+5fLPkvAbjs7YjgMoB8dsIwW2Z5X7KIRFWEwrf2oEyhXaZX5ZrOZoBc4rcjzKE7tt0jF6XpoJWtMTIg== 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=d9fYai2J/9ZZQyO2LFi8mKTVQR9Pcq5+fwt2d22slwY=; b=XgEcc7mUK1vnf0p1UM7oLCPpmh9GUvaXi0qT2GalEBLeTNl0qMpvfqAWVJwkp9NSZWQFLLf/blo5gYVGsvKoudoiThbh/T9LlB9OvArXdhrsHCTnjQO1K2WykavGztR8QMUqlqGkhhprXpbk+SWCZGaBYdajdw2HGZ38CHgAogHRlBdmaD4vHrIMGswGRXfo+J0gIeQ2x21ULbsWeCGUQbIPLngv2J8iG77wfgjwp+VjusA2U/saaE280XfrboCYuT3aSZh2yptVN26yLrkvAj5+/AffMWZH8QTkZi18dCwRlzl6p9yYddTq48NCTH3xk7BM4NFHkdhv4aVl7+0+vg== 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=d9fYai2J/9ZZQyO2LFi8mKTVQR9Pcq5+fwt2d22slwY=; b=meJv4P6kPCIIW4gn07Ra6E0jJi7zKsADZIQ4UFliWzWbxvskU7RCzhgwoYwT8OSOvZFDuJSLRjXcIFwGzapCvePG8FNG96l7CStzu5R12U14kBppFuaeZaaBUVhbXS4H4jK4KRRV63m6gSY/W9kBPXFkAf57qTrY7HbW2/EEiIaSr2kfSWKRkGfHYFRsXxs4JzsCeL3zluuapNnHCJzHnIjQ5YW9qtdnegrIFjahksL6vctiHsUr7Yh/MaOMLRnUzEwm1VKCn0AEzJSKnMF1VOTWjzfkbdqGDgVVGC4579Q19nrOSpCM32GMmNb16dp53/+s0ITZgAwVwu8TScTEmA== Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) by PR3P250MB0132.EURP250.PROD.OUTLOOK.COM (2603:10a6:102:177::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.5676.17; Wed, 28 Sep 2022 18:43:04 +0000 Received: from GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::68bd:2fc7:ac52:38f8]) by GV1P250MB0737.EURP250.PROD.OUTLOOK.COM ([fe80::68bd:2fc7:ac52:38f8%9]) with mapi id 15.20.5654.025; Wed, 28 Sep 2022 18:43:03 +0000 From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 28 Sep 2022 20:43:00 +0200 Message-ID: X-Mailer: git-send-email 2.34.1 In-Reply-To: References: X-TMN: [jZD22S2Gu1Ql7pRqCeyZjGbM2w+zrq3INVImG5tMG/s=] X-ClientProxiedBy: AM6P192CA0099.EURP192.PROD.OUTLOOK.COM (2603:10a6:209:8d::40) To GV1P250MB0737.EURP250.PROD.OUTLOOK.COM (2603:10a6:150:8e::17) X-Microsoft-Original-Message-ID: <20220928184300.937509-2-andreas.rheinhardt@outlook.com> MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: GV1P250MB0737:EE_|PR3P250MB0132:EE_ X-MS-Office365-Filtering-Correlation-Id: c414e70f-680b-493d-89ac-08daa18146d8 X-MS-Exchange-SLBlob-MailProps: AZnQBsB9XmpPcoZqFl/i/jhf7c/pX34TiGRS9/yMDyRqZOza1UCpYM5GnrkwEqAkM+DOJOPahEWLa2ifpiZt+N2zCV6yOKAJf6nxc1HdHcC8kYbKlYTGRwW0n/d8Y/TCKn0A/Q0Codvp4eXnHVnPEDqUHRmW55laE9MmQoG4I2efM4FsMb52w1qDLjYcM/bantpa2gOScKLD+lSrvJUzPqtQaK24qlhLpzy9UdPCmnqKOr7n+PuLXRGCn6IhOIpKwfyWN61oq1bgTGChLXBJqZPjeT2S1ZpVUPUomcAVBItZpmxwDD21A0IiFQtlgcOVg+RcHMC+OCCeyvlxjAhb0yflT/Pqg2hjk7By6Sv2F9XY0ah8U9KmGUq1nJw/zVwigK5enxe0KKylaUx6N4KJS+Bz51DBDihDGLMWl+yF3o64LFD8+rhfThzR7/fiYvw8Z1G7oz0XQbHRjHCR6RWu2oMSJK24xJ1SUnn15V1+oCpB9yHNKqzhpKw8FtAUTC+XaKL20JCOIDzUFcSul4gchwVYHW3ewL6R0RFBmA0YHfkSaIxxqvM3KNkXd7NYujxKAzYrZW8Za7LP+sMyKuIuFvN6MzI2dWzEdyJNoecppDPH+zNVSWnzZQkbaWv1cMo/8czEfCshRuoOLyQhP9zCqQMZuoxDvoY/UQ+FpJ/CJ8Dp+gFzCDpG34xw3gb22m2R5CgQ6NLDOJ4KNt0mZnljvtmYsO6MX+XEQlSfjMmWh201v+lgLixMdZeV02VU8vsUj4ERCBVe0+0= X-Microsoft-Antispam: BCL:0; X-Microsoft-Ant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Exchange-CrossTenant-AuthSource: GV1P250MB0737.EURP250.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Sep 2022 18:43:03.9514 (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: PR3P250MB0132 Subject: [FFmpeg-devel] [PATCH 3/3] avcodec/wmalosslessdec: Simplify flushing, avoid NULL + 0 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: qj3Tp7V3br7/ Return immediately if not enough leftover bits are available when flushing. This is simpler and also avoids an init_get_bits(gb, NULL, 0) (which currently leads to NULL + 0, which is UB; this affects the lossless-wma(|-1|-2|-rawtile) FATE tests). Signed-off-by: Andreas Rheinhardt --- libavcodec/wmalosslessdec.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/libavcodec/wmalosslessdec.c b/libavcodec/wmalosslessdec.c index 5112b763fa..d545d848e2 100644 --- a/libavcodec/wmalosslessdec.c +++ b/libavcodec/wmalosslessdec.c @@ -1192,16 +1192,15 @@ static int decode_packet(AVCodecContext *avctx, AVFrame *rframe, s->frame->nb_samples = 0; - if (!buf_size && s->num_saved_bits > get_bits_count(&s->gb)) { + if (!buf_size) { s->packet_done = 0; + if (s->num_saved_bits <= get_bits_count(&s->gb)) + return 0; if (!decode_frame(s)) s->num_saved_bits = 0; } else if (s->packet_done || s->packet_loss) { s->packet_done = 0; - if (!buf_size) - return 0; - s->next_packet_start = buf_size - FFMIN(avctx->block_align, buf_size); buf_size = FFMIN(avctx->block_align, buf_size); s->buf_bit_size = buf_size << 3; @@ -1299,7 +1298,7 @@ static int decode_packet(AVCodecContext *avctx, AVFrame *rframe, s->packet_offset = get_bits_count(gb) & 7; - return (s->packet_loss) ? AVERROR_INVALIDDATA : buf_size ? get_bits_count(gb) >> 3 : 0; + return (s->packet_loss) ? AVERROR_INVALIDDATA : get_bits_count(gb) >> 3; } static void flush(AVCodecContext *avctx)