From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 4597B48D8E for ; Fri, 26 Jan 2024 16:21:02 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9C3E068D146; Fri, 26 Jan 2024 18:20:59 +0200 (EET) Received: from sender11-op-o12.zoho.eu (sender11-op-o12.zoho.eu [31.186.226.226]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1CAFC68BCC3 for ; Fri, 26 Jan 2024 18:20:53 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; t=1706286051; cv=none; d=zohomail.eu; s=zohoarc; b=dPRZCI18WW6FPwNm9LPwuax9A9EE1Zv+bF0l8jjfnhWOBrGY0Z2Xd/IxG3h3AUNZcQMeW0AMCRo3IeEWaWmRFSY30U6gFIdiklXZBqusqsdObsH1ETPGlih6TOsckwlTx/gi3KQm7auNcfODvS7vG9vvunCJOX11f9VZEESPaBY= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.eu; s=zohoarc; t=1706286051; h=Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:MIME-Version:Message-ID:Subject:Subject:To:To:Message-Id:Reply-To; bh=dy/RBFxBtc4vRvtr+vVP+BdIEz49pdcJ7uxSXEbOcO0=; b=a/tw0uh/y9UXJa6ZUdBGqGGcFaoaCg2c6y0UT4We4qtfg9TsA5PRTAVCjNkqYKuhxvf6j5fnXmfTLtzpWpAjsdfeCDbEDgD10SPCkME0Pv+mkVW7vXIbAwD/mikaX397kbkacfphFx1aitQyFkSgVI0mEm9isnmC83WPc7QS/Uc= ARC-Authentication-Results: i=1; mx.zohomail.eu; dkim=pass header.i=frankplowman.com; spf=pass smtp.mailfrom=post@frankplowman.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1706286051; s=zmail; d=frankplowman.com; i=post@frankplowman.com; h=From:From:To:To:Cc:Cc:Subject:Subject:Date:Date:Message-ID:MIME-Version:Content-Transfer-Encoding:Message-Id:Reply-To; bh=dy/RBFxBtc4vRvtr+vVP+BdIEz49pdcJ7uxSXEbOcO0=; b=I0FWUzGNE4EEQS23nxCawRfhIjsrB3OjWNZLZRYXv++qI5g2deuid75n0UcX3Oxd 9uQykfGAos2tWJrUc+TTesh15i28peKLVE6pMVpH57SLjbOT8tnepcmzn3Jr0OTmdLG HTGTAw8QdNCvl0XVggB/rJzt/mzpoBqGV+WhuptA= Received: from localhost.localdomain (frankplowman.com [51.89.148.29]) by mx.zoho.eu with SMTPS id 1706286049943962.5699342649904; Fri, 26 Jan 2024 17:20:49 +0100 (CET) From: post@frankplowman.com To: ffmpeg-devel@ffmpeg.org Date: Fri, 26 Jan 2024 16:20:43 +0000 Message-ID: <20240126162043.59687-1-post@frankplowman.com> X-Mailer: git-send-email 2.43.0 MIME-Version: 1.0 X-ZohoMailClient: External Subject: [FFmpeg-devel] [PATCH] lavc/vvc: Fix emulation prevention byte handling 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: Frank Plowman Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: From: Frank Plowman nal->skipped_bytes_pos contains the positions of errors relative to the start of the slice header, whereas the position they were tested against is relative to the start of the slice data, i.e. one byte after the end of the slice header. Patch fixes this by storing the size of the slice header in H266RawSlice and adding it to the position given by the GetBitContext before comparing to skipped_bytes_pos. This fixes AVERROR_INVALIDDATAs for various valid bitstreams, such as the LMCS_B_Dolby_2 conformance bitstream. Signed-off-by: Frank Plowman --- libavcodec/cbs_h2645.c | 1 + libavcodec/cbs_h266.h | 1 + libavcodec/vvc/vvcdec.c | 9 +++++---- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c index c48a06b241..2fb249bcd3 100644 --- a/libavcodec/cbs_h2645.c +++ b/libavcodec/cbs_h2645.c @@ -1155,6 +1155,7 @@ static int cbs_h266_read_nal_unit(CodedBitstreamContext *ctx, return err; } + slice->header_size = pos / 8; slice->data_size = len - pos / 8; slice->data_ref = av_buffer_ref(unit->data_ref); if (!slice->data_ref) diff --git a/libavcodec/cbs_h266.h b/libavcodec/cbs_h266.h index 8b3ad391b1..73d94157d4 100644 --- a/libavcodec/cbs_h266.h +++ b/libavcodec/cbs_h266.h @@ -843,6 +843,7 @@ typedef struct H266RawSlice { uint8_t *data; AVBufferRef *data_ref; + size_t header_size; size_t data_size; int data_bit_start; } H266RawSlice; diff --git a/libavcodec/vvc/vvcdec.c b/libavcodec/vvc/vvcdec.c index 540a05f8cf..83ee472ce6 100644 --- a/libavcodec/vvc/vvcdec.c +++ b/libavcodec/vvc/vvcdec.c @@ -451,8 +451,9 @@ static int slices_realloc(VVCFrameContext *fc) } static void ep_init_cabac_decoder(SliceContext *sc, const int index, - const H2645NAL *nal, GetBitContext *gb) + const H2645NAL *nal, GetBitContext *gb, const CodedBitstreamUnit *unit) { + const H266RawSlice *slice = unit->content_ref; const H266RawSliceHeader *rsh = sc->sh.r; EntryPoint *ep = sc->eps + index; int size; @@ -461,10 +462,10 @@ static void ep_init_cabac_decoder(SliceContext *sc, const int index, int skipped = 0; int64_t start = (gb->index >> 3); int64_t end = start + rsh->sh_entry_point_offset_minus1[index] + 1; - while (skipped < nal->skipped_bytes && nal->skipped_bytes_pos[skipped] <= start) { + while (skipped < nal->skipped_bytes && nal->skipped_bytes_pos[skipped] <= start + slice->header_size) { skipped++; } - while (skipped < nal->skipped_bytes && nal->skipped_bytes_pos[skipped] < end) { + while (skipped < nal->skipped_bytes && nal->skipped_bytes_pos[skipped] <= end + slice->header_size) { end--; skipped++; } @@ -506,7 +507,7 @@ static int slice_init_entry_points(SliceContext *sc, fc->tab.slice_idx[rs] = sc->slice_idx; } - ep_init_cabac_decoder(sc, i, nal, &gb); + ep_init_cabac_decoder(sc, i, nal, &gb, unit); if (i + 1 < sc->nb_eps) ctu_addr = sh->entry_point_start_ctu[i]; -- 2.43.0 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".