From patchwork Fri Mar 10 09:17:53 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Gaullier X-Patchwork-Id: 40631 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:d046:b0:cd:afd7:272c with SMTP id hv6csp1024305pzb; Fri, 10 Mar 2023 01:18:22 -0800 (PST) X-Google-Smtp-Source: AK7set8IH15CaAAfvlOpFACGQtFNnf49tuqO/oKTS40AZLgWEQww4XDP8o50RSv0UMRIgNraaRxU X-Received: by 2002:a17:906:9744:b0:885:fee4:69ee with SMTP id o4-20020a170906974400b00885fee469eemr28915150ejy.59.1678439902081; Fri, 10 Mar 2023 01:18:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678439902; cv=none; d=google.com; s=arc-20160816; b=BlkHpRDE6WWX/c2G73Rcomx9ztnmcZEEWitxXyqMPJjOZD26TSLxSiynReliafcAws mRZ1VWEwmuA4BBwlMaJ2HHh5OyRKayp5tBJb6lDMPuUAKkup+WIFmf9EddzG7KiRtbPK MUbwvr1sWY1zP2AqH7SBnT3n42Cwel8U0j+yMuWzPqjFqcuPC9rHl5KtSPFwJZTcYeuG Dn7ajWw+fhk/Edj1VeU4d1X60xzys1HSmKnXwlXUW5Wbhnk+2gkMw/4tvBxDI0Mj44Y3 74AH1Z/bsZl2EiXy2xD67Jt6FM2X4Q+ZhcJrekLLwIs/+oxuxdu0efOU6D+3ZCLJ1GhK bDaw== 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:references:in-reply-to :message-id:date:to:from:delivered-to; bh=KQo4ayctJn1w/OxQv0WvsAkrilZZsrE4jlUf6huEH3s=; b=yVLCL3nHHixPM/7wpVTN02MOX0UjUs+AWpMQaf/2hkmqU0rGnihsanVnEIL2HugMZu wI/Vk8MEc298sQC+4xF1cBT/eWlc6cu9+ckiLb6Ed4Bp1dfK7OVryj/rLq0geVAR06kW e1fGo8gv8r0ky6E+S6vLA86twtdtQlxyXaY26TmUmDoskWTx4dKoRU8cgv4dOh0ii2Rw cZIjOhDUyIMsFXVekMMrx3rxtK97aN5Zr3k+LHOm7K/+YlpzH144DjryJKYa2cOfELqF scC2NE0CcX4iwqNmqIVG/3vbe24/RV48r1iRmqMa1nsrgR0QDQdl1HM9HXtJd1wOa47Y iMow== 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 j12-20020a170906278c00b008ba23e0d9b7si1634110ejc.469.2023.03.10.01.18.21; Fri, 10 Mar 2023 01:18:22 -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; 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 2538C68BDD8; Fri, 10 Mar 2023 11:18:07 +0200 (EET) 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 F039368BD27 for ; Fri, 10 Mar 2023 11:17:59 +0200 (EET) Received: from cji.paris (unknown [172.16.3.159]) by srv-infra-1.infra.inf.glb.tvvideoms.com (Postfix) with ESMTP id 04C822B0F5; Fri, 10 Mar 2023 09:17:58 +0000 (UTC) From: Nicolas Gaullier To: ffmpeg-devel@ffmpeg.org Date: Fri, 10 Mar 2023 10:17:53 +0100 Message-Id: <20230310091753.10230-2-nicolas.gaullier@cji.paris> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230310091753.10230-1-nicolas.gaullier@cji.paris> References: <20230310091753.10230-1-nicolas.gaullier@cji.paris> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 1/1] 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: gIs0/2S+o4yU 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 | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/libavcodec/dolby_e.c b/libavcodec/dolby_e.c index 921c33f3ba..a24edfcc93 100644 --- a/libavcodec/dolby_e.c +++ b/libavcodec/dolby_e.c @@ -845,6 +845,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; @@ -885,6 +886,14 @@ 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; }