From patchwork Tue Apr 5 06:49:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Xiaolei Yu X-Patchwork-Id: 35206 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:c05:b0:7a:e998:b410 with SMTP id bw5csp131228pzb; Mon, 4 Apr 2022 23:50:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyGVfWmhCViS2z3QMDYerF2AmFGo/bG85YLA9RB0WA9a/X37J/PjFAsSdTKy90G3VJOYWnh X-Received: by 2002:a17:907:6284:b0:6e0:f895:15a with SMTP id nd4-20020a170907628400b006e0f895015amr1993590ejc.713.1649141402418; Mon, 04 Apr 2022 23:50:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1649141402; cv=none; d=google.com; s=arc-20160816; b=MdwkLfIwa+jYHz6zlCYiqt39jixG3820k3DJwOz9lfcYLfX7PK6Nv+tvj0jGdAhTDo akiviQf0nL3jBWaq3KD/f2uXpoObc8b9ALoII43iJjKJLHq7c+ndc9TdN5xirMU88OL3 xltik8vTt25jfDeirjqG/zS7KJKFPOpS+AvZKE5uuZndfg2kVcx2B81FkxMA2cmxuowh DpiocOugP87iimsIwn0Ab/N/ghHjhTSW4ftbr25c4yRPjuFVDNQjcoQdvFYglDoJgnch FtseXw/4wIluSrAE5gxgPvfVUvFVo+05CJgwmogNBLmZCiQQUUwHFx3tzbpPPtoA+VDb HjrA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:from:to:content-language:user-agent:mime-version :date:message-id:dkim-signature:delivered-to; bh=bIQBoLm3HKNdgnT8+Vm8binDMW56B6p10Poq/e2UwsI=; b=jmKyYboxLLV7unVMPJxw7z4AcHqb3VlscpkQvT/musjSJKEXZgQznCggsajXPgpcp6 Fhl2hgSZjdgodbE98eGtArMXc539h98O6WIyROh66VDqUdORuFsh/sqTPDHorrCW1joD bznNzaPu2c/XgpfxGI2bQ+/Zu2WUciTy3uibT/QBMBwaPn8Rpffb1ME9OI/S1Ld/YSGc 7Tj4tChcp47k+WZHXKrU0dS5qgzK1aq5FZ6sfY5qhebn6RdOucVMU584ABTnkKDoio01 TW8oa0tB/BuCfrHfOFgKvH3yI1qCOTCoGcVMfjBzsgTBEB1BitondqC/CLQiyBWzRLYw RgCA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20210112 header.b=FVrxsChr; 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=gmail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id i13-20020a50e14d000000b00418c2b5bdefsi8458083edl.209.2022.04.04.23.49.38; Mon, 04 Apr 2022 23:50:02 -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=@gmail.com header.s=20210112 header.b=FVrxsChr; 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=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 30FE168B24D; Tue, 5 Apr 2022 09:49:36 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-pj1-f46.google.com (mail-pj1-f46.google.com [209.85.216.46]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 99A8168B120 for ; Tue, 5 Apr 2022 09:49:29 +0300 (EEST) Received: by mail-pj1-f46.google.com with SMTP id 2so3749014pjw.2 for ; Mon, 04 Apr 2022 23:49:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:date:mime-version:user-agent:content-language:to:from :subject:content-transfer-encoding; bh=IN3omPE5CMHjrgac6jJxMABXDP4I047iexa5EN0p1Hk=; b=FVrxsChryuAhRQr9sHTNqHholW3JLd5YCeOEqyk+ae8Yeyob3I2Lze1j6J5eKGyk+Z 93n7Tv2WjXENFYMmbenBC9mbXIYUY05To570OiF2pRgOnAJw2vadXkTfVcSTZyxeYNcC ZfRaUNDJ31qatjfrot1ZTPkCvCdWLPF+gGpBBALdjCo2irPoDX6PYiPuAsTllOIsaNxz gZDLIxXvBftWibUz9/CPJQflkOuOtZ7ZVm3PX8Ryet6QlmNjQiJppd0zhR0gmL3iLTQP pT3WnBlhLqA61A6RPe3M3ppNUYe/MmU6LhWsx6xIED3DR3ka9qx0mKhjtXw3dk/2VOYW ghJA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent :content-language:to:from:subject:content-transfer-encoding; bh=IN3omPE5CMHjrgac6jJxMABXDP4I047iexa5EN0p1Hk=; b=g+bC9f9il0QxC8V90PZB8mJWL4oEkbzuqLggmDeki6KIrOSbzTtt21LO9yAnMJ9HBq 7jJrbogLzLYBx4W4y08fQpoJwhkZzOHPIRvv5dya30/EM3hwae88Xv/CfkQ1FgtzFuZj Co3NCUkBLdED5iCD0x80VjMQgM/4GxJ5RaH01no762arOS+z6+qfP94LlnoUlRDphjgp 8M8ady2d3LDdxYPSNcYsus51xqdSUGzZj6jJ2GzJtwCN7QkFJ1+5jOUKtY4lgtUntI8O YqxPtX93y1mBFpchFneLZBG7RXpBnGLagyikb0VzXaDCfF2euLjWltsdvi2zs+DCDkVv BvnQ== X-Gm-Message-State: AOAM533b59gZCl84z/5jhbSZu9UxtPii207uD5pvYQ8BffGR4ZuCddPq vJqU8sbqGg8B/tX/S+wzBGXlAc2tLtPw4g== X-Received: by 2002:a17:903:244b:b0:154:2cb2:86d with SMTP id l11-20020a170903244b00b001542cb2086dmr1989867pls.123.1649141367779; Mon, 04 Apr 2022 23:49:27 -0700 (PDT) Received: from [192.168.247.14] ([47.246.98.230]) by smtp.gmail.com with ESMTPSA id pj9-20020a17090b4f4900b001c744034e7csm1257898pjb.2.2022.04.04.23.49.26 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 04 Apr 2022 23:49:27 -0700 (PDT) Message-ID: <5ca902bc-99cc-2866-ec9a-068ac356924d@gmail.com> Date: Tue, 5 Apr 2022 14:49:24 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Content-Language: en-US To: ffmpeg-devel@ffmpeg.org From: Xiaolei Yu Subject: [FFmpeg-devel] [PATCH] libavcodec/hevcdec: detect non-conformant missing refs 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: Ct5KD8ZAmbrx For cases which prefer rejecting broken bitstreams. --- libavcodec/hevc_refs.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/libavcodec/hevc_refs.c b/libavcodec/hevc_refs.c index fe18ca2b1d..7ea70e301b 100644 --- a/libavcodec/hevc_refs.c +++ b/libavcodec/hevc_refs.c @@ -426,7 +426,7 @@ static HEVCFrame *generate_missing_ref(HEVCContext *s, int poc) /* add a reference with the given poc to the list and mark it as used in DPB */ static int add_candidate_ref(HEVCContext *s, RefPicList *list, - int poc, int ref_flag, uint8_t use_msb) + int poc, int ref_flag, uint8_t use_msb, int maybe_missing) { HEVCFrame *ref = find_ref_idx(s, poc, use_msb); @@ -434,6 +434,9 @@ static int add_candidate_ref(HEVCContext *s, RefPicList *list, return AVERROR_INVALIDDATA; if (!ref) { + if ((s->avctx->err_recognition & AV_EF_COMPLIANT) && !maybe_missing) + return AVERROR_INVALIDDATA; + ref = generate_missing_ref(s, poc); if (!ref) return AVERROR(ENOMEM); @@ -476,6 +479,7 @@ int ff_hevc_frame_rps(HEVCContext *s) for (i = 0; i < short_rps->num_delta_pocs; i++) { int poc = s->poc + short_rps->delta_poc[i]; int list; + int maybe_missing; if (!short_rps->used[i]) list = ST_FOLL; @@ -484,7 +488,10 @@ int ff_hevc_frame_rps(HEVCContext *s) else list = ST_CURR_AFT; - ret = add_candidate_ref(s, &rps[list], poc, HEVC_FRAME_FLAG_SHORT_REF, 1); + maybe_missing = list != ST_CURR_BEF && list != ST_CURR_AFT; + + ret = add_candidate_ref(s, &rps[list], poc, HEVC_FRAME_FLAG_SHORT_REF, 1, + maybe_missing); if (ret < 0) goto fail; } @@ -493,8 +500,10 @@ int ff_hevc_frame_rps(HEVCContext *s) for (i = 0; i < long_rps->nb_refs; i++) { int poc = long_rps->poc[i]; int list = long_rps->used[i] ? LT_CURR : LT_FOLL; + int maybe_missing = list != LT_CURR; - ret = add_candidate_ref(s, &rps[list], poc, HEVC_FRAME_FLAG_LONG_REF, long_rps->poc_msb_present[i]); + ret = add_candidate_ref(s, &rps[list], poc, HEVC_FRAME_FLAG_LONG_REF, long_rps->poc_msb_present[i], + maybe_missing); if (ret < 0) goto fail; }