From patchwork Tue Sep 13 21:31:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Gaullier X-Patchwork-Id: 37908 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:3b1c:b0:96:9ee8:5cfd with SMTP id c28csp951251pzh; Tue, 13 Sep 2022 14:31:40 -0700 (PDT) X-Google-Smtp-Source: AA6agR770JBpgebEA8a1q96ufL01QMzjzP8NaxVtz6IPqrvoKBWwlH2q2jik1kkRQtxBS3319+Me X-Received: by 2002:a05:6402:51c6:b0:451:6379:81cb with SMTP id r6-20020a05640251c600b00451637981cbmr14002850edd.372.1663104700260; Tue, 13 Sep 2022 14:31:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663104700; cv=none; d=google.com; s=arc-20160816; b=ubENcatTsV8z4Qd/D6VbOcO9aErhXTZysEQZYFOHyFXO7rZXikyUDuD8AA6doEFiUz g8CH/TiHkE1lC9HkyT+IC92Kud11pu3vw9yMTkzRROYTqeeH1wgznkKY1JcyludGx1wL /LEb/AZQVJSVVaP4whrQnpvcKZbWrH5iJjHgfzzpz1hUGFCWu8sSjkIsU327KpfgvvmG ZbkX6gZRXJrVkchOWSHjWfawzEVOKrruZNhQiyKeYncax+tv5dCB+v/ev8n3vT0S9hL0 a31jA0RC9xZVnh2rmTfs0F2tdJKTWA9Nv9j/NkeJ18pV97zptwojqc8NAQNDSf4Vh6wh iVzg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :delivered-to; bh=St0dW/Lz/dxVAIqrSIuF0GbOLX2pzdLv76481jwpW1E=; b=I3rB57Kx+qRCyFWoq6LhRIM7Bcjd4YoiBHpcuipw3WP4lmznusPrqZNLio7YCf0hQi jkxQRwyMwWuREwAZSUYHrTAEd90fMtx7fTqoI2eY0lAUjtEfkUgyBHqeEuLF1mQervqD wUibrtVzoUrhwXsT/qVQtGjkXE3e/eyELFT1lnVmCRVIsnLvxwuDM0LBcVCcxq9cYnMY UP1Ywg0HYLjOiCv17E1uJgXW0Nht4NjKZDMplLFPTMspx9rHqOvu8i214yqZdf0LxC1I YMxSSJRz8PFuU1IcKvCh+ufzo+3aZqju4Vs2Yt0+OgMv7LX3jNqSf6Ni+mvFE+Xv9o2W 2vgg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id o26-20020a17090637da00b0076f0a8679ecsi9130042ejc.875.2022.09.13.14.31.39; Tue, 13 Sep 2022 14:31:40 -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; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 427CE68BAC3; Wed, 14 Sep 2022 00:31:36 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from srv-infra-1.infra.inf.glb.tvvideoms.com (www.inf.tvvideoms.com [213.205.126.156]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2255868B32D for ; Wed, 14 Sep 2022 00:31:29 +0300 (EEST) Received: from cji.paris (unknown [172.16.3.159]) by srv-infra-1.infra.inf.glb.tvvideoms.com (Postfix) with ESMTP id 1C9D229D55; Tue, 13 Sep 2022 21:31:29 +0000 (UTC) From: Nicolas Gaullier To: ffmpeg-devel@ffmpeg.org Date: Tue, 13 Sep 2022 23:31:27 +0200 Message-Id: <20220913213127.1756-1-nicolas.gaullier@cji.paris> X-Mailer: git-send-email 2.37.2.windows.2 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] avcodec/dolby_e: Add error recovery when parse_mantissas run out of bits 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: Nicolas Gaullier Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: T0icdBkoG7J8 Mantissas are the last data in the channel subsegment and it appears it is sometimes missing a very few bits for the parsing to complete. This should not be confused with data corruption. For 5.1+2@25fps, the occurence of this issue is pretty steady and about once every 2 hours. The truncation is at about 950 out of the 1024 values (never seen below 923 so far). The current code raises a severe 'Read past end' error and all data is lost resulting in 20ms(@25fps) of silence for the affected channel. This patch introduces a tolerance: if 800 out of the 1024 mantissas have been parsed, a simple warning is raised and the data is preserved. Signed-off-by: Nicolas Gaullier --- libavcodec/dolby_e.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/libavcodec/dolby_e.c b/libavcodec/dolby_e.c index 06f4fdd44f..0ec7b5e318 100644 --- a/libavcodec/dolby_e.c +++ b/libavcodec/dolby_e.c @@ -844,6 +844,7 @@ static int parse_indices(DBEContext *s, DBEChannel *c) return 0; } +#define MIN_MANTISSAS 800 static int parse_mantissas(DBEContext *s, DBEChannel *c) { DBEGroup *g; @@ -884,6 +885,13 @@ static int parse_mantissas(DBEContext *s, DBEChannel *c) } } } else { + if (i == c->nb_groups - 1 + && count * size1 > get_bits_left(&s->gb) + && get_bits_left(&s->gb) >= 0 + && (int)(mnt - c->mantissas) >= MIN_MANTISSAS) { + av_log(s->avctx, AV_LOG_WARNING, "Truncated mantissas @%d, highest frequencies not recoverable\n", (int)(mnt - c->mantissas)); + break; + } for (k = 0; k < count; k++) mnt[k] = get_sbits(&s->gb, size1) * scale; }