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 92FD246D4C for ; Wed, 9 Aug 2023 17:08:37 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8C53568C70C; Wed, 9 Aug 2023 20:08:34 +0300 (EEST) Received: from mail-ot1-f43.google.com (mail-ot1-f43.google.com [209.85.210.43]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id A52C368C558 for ; Wed, 9 Aug 2023 20:08:27 +0300 (EEST) Received: by mail-ot1-f43.google.com with SMTP id 46e09a7af769-6bca857accbso28475a34.0 for ; Wed, 09 Aug 2023 10:08:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691600905; x=1692205705; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id:from :to:cc:subject:date:message-id:reply-to; bh=aNRMZsJ7f/ON9mainB2klH2mpwS/mlj3Lc95kDhi6Fc=; b=JjPGDkYsHzKnjrOew3Q2IW/p5EjSRtJFV3vuV4KFW+uSHh+xkuwNowrjkKtGiUQjpq XLoPGM8mTp37jgRUvIfn30snB65LIFrwuGHugC0inh92NVAa2Qah+cV3YYk2ecnl6SYk QAePt6KgqLwR5NWCopwRBfXhCogov6d5mBbMEv97Kfk9b9llUrYDtCkkmnxiO6gaEOIT +kmDiIz7sPjlNJMVi6U4RDt4MV6TvgXq081Hf+pS970Ls1cwt0Ris1OutVgKJGf47vAs lTzecn6feBfX5hEds5zvUG81onpj10z/EgQ6IH81AaryBu7fVruFNLsrd69DeOyQGaOP DJ5g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691600905; x=1692205705; h=content-transfer-encoding:in-reply-to:from:content-language :references:to:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=aNRMZsJ7f/ON9mainB2klH2mpwS/mlj3Lc95kDhi6Fc=; b=jybM/cquDr/NL9dHa9gikA58IomwXVIqSWyMO52lOoKTv5zScEw50vxwqRpAPw/WXL 6X0WLtfwtwoSkb+I4/55Xa649OXboXkeQMYwnryRZZ5zSgNPXtFYeL2MAQUQRT2Fw0H1 jW0/PUrfbd4ivCoeW39bEF95md5oGWEeM3z1jaX6gnwsCiatGfBi7LjlDp06rh4ciSjH p6AXVfMhXCeK27Ltr90jZkyhE8skD8o4H64SufFQRhwWD0t1PD/vv5jgdQGV6PCaQ/zB KRjR1G16Q6QndTnTZhPVcJJX/e7JD5vUlhNVBvamXf1ezRqwEizinx5ebjqQZJ0C687v Lgnw== X-Gm-Message-State: AOJu0YyG0kkd3CAz869A0XA5deGdwjOEpWv6qTJPGsIbskeVwO+lF5x5 i06cW34mgYvCvbB6UGbkHFCS2cBRBc0= X-Google-Smtp-Source: AGHT+IFHOPAZzBywEBWb9mqWF5F31ZJEdVHFsM8RUeitv99gcYap4z5yHfDxLl0XNJiowgfgyPO23Q== X-Received: by 2002:a9d:4d82:0:b0:6b9:e412:b02b with SMTP id u2-20020a9d4d82000000b006b9e412b02bmr3778774otk.2.1691600905295; Wed, 09 Aug 2023 10:08:25 -0700 (PDT) Received: from [192.168.0.16] (host197.190-225-105.telecom.net.ar. [190.225.105.197]) by smtp.gmail.com with ESMTPSA id e14-20020a0568301e4e00b006b29a73efb5sm7044101otj.7.2023.08.09.10.08.24 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 09 Aug 2023 10:08:24 -0700 (PDT) Message-ID: Date: Wed, 9 Aug 2023 14:08:25 -0300 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.14.0 To: ffmpeg-devel@ffmpeg.org References: <20230809170500.24407-1-tcChlisop0@gmail.com> Content-Language: en-US From: James Almer In-Reply-To: <20230809170500.24407-1-tcChlisop0@gmail.com> Subject: Re: [FFmpeg-devel] [PATCH v2] avcodec/dovi_rpu: verify RPU data CRC32 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 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On 8/9/2023 2:05 PM, quietvoid wrote: > The Dolby Vision RPU contains a CRC32 to validate the payload against. > The implementation is CRC32/MPEG-2. > > The CRC is only verified with the AV_EF_CRCCHECK flag. > > Signed-off-by: quietvoid > --- > libavcodec/dovi_rpu.c | 45 ++++++++++++++++++++++++++++++++++++++++--- > libavcodec/dovi_rpu.h | 3 ++- > libavcodec/hevcdec.c | 3 ++- > 3 files changed, 46 insertions(+), 5 deletions(-) > > diff --git a/libavcodec/dovi_rpu.c b/libavcodec/dovi_rpu.c > index dd38936552..9ada0aceec 100644 > --- a/libavcodec/dovi_rpu.c > +++ b/libavcodec/dovi_rpu.c > @@ -22,6 +22,7 @@ > */ > > #include "libavutil/buffer.h" > +#include "libavutil/crc.h" > > #include "dovi_rpu.h" > #include "golomb.h" > @@ -191,13 +192,17 @@ static inline int64_t get_se_coef(GetBitContext *gb, const AVDOVIRpuDataHeader * > } \ > } while (0) > > -int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size) > +int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size, > + int err_recognition) > { > AVDOVIRpuDataHeader *hdr = &s->header; > GetBitContext *gb = &(GetBitContext){0}; > DOVIVdrRef *vdr; > int ret; > > + size_t actual_rpu_size; > + uint8_t trailing_zeroes = 0; > + > uint8_t nal_prefix; > uint8_t rpu_type; > uint8_t vdr_seq_info_present; > @@ -205,7 +210,22 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size) > uint8_t use_prev_vdr_rpu; > uint8_t use_nlq; > uint8_t profile; > - if ((ret = init_get_bits8(gb, rpu, rpu_size)) < 0) > + > + uint32_t rpu_data_crc32; > + uint32_t computed_crc32; > + > + for (int i = rpu_size - 1; i > 0; i--) { > + if (!rpu[i]) { > + trailing_zeroes++; > + } else { > + break; > + } > + } > + > + actual_rpu_size = rpu_size - trailing_zeroes; > + > + /* Exclude trailing byte (0x80) from reader */ > + if ((ret = init_get_bits8(gb, rpu, actual_rpu_size - 1)) < 0) > return ret; > > /* RPU header, common values */ > @@ -440,7 +460,26 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size) > color->source_diagonal = get_bits(gb, 10); > } > > - /* FIXME: verify CRC32, requires implementation of AV_CRC_32_MPEG_2 */ > + /* Skip unsupported until CRC32 */ > + skip_bits_long(gb, get_bits_left(gb) - 32); This can be done after the err_recognition check. > + > + if (err_recognition & AV_EF_CRCCHECK) { Do instead if (!(err_recognition & AV_EF_CRCCHECK)) return 0; To remove one level of indentation. > + rpu_data_crc32 = get_bits_long(gb, 32); > + > + /* Verify CRC32, buffer excludes the prefix, CRC32 and trailing byte */ > + computed_crc32 = av_bswap32(av_crc(av_crc_get_table(AV_CRC_32_IEEE), > + -1, rpu + 1, actual_rpu_size - 6)); > + > + if (rpu_data_crc32 != computed_crc32) { > + av_log(s->logctx, AV_LOG_ERROR, > + "RPU CRC mismatch! Expected %"PRIu32", received %"PRIu32"\n", > + rpu_data_crc32, computed_crc32); > + > + if (err_recognition & AV_EF_EXPLODE) > + goto fail; > + } > + } > + > return 0; > > fail: > diff --git a/libavcodec/dovi_rpu.h b/libavcodec/dovi_rpu.h > index f6ca5bbbc5..2b993a72c6 100644 > --- a/libavcodec/dovi_rpu.h > +++ b/libavcodec/dovi_rpu.h > @@ -77,7 +77,8 @@ void ff_dovi_update_cfg(DOVIContext *s, const AVDOVIDecoderConfigurationRecord * > * > * Returns 0 or an error code. > */ > -int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size); > +int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size, > + int err_recognition); > > /** > * Attach the decoded AVDOVIMetadata as side data to an AVFrame. > diff --git a/libavcodec/hevcdec.c b/libavcodec/hevcdec.c > index df40c91ba6..81b1a84625 100644 > --- a/libavcodec/hevcdec.c > +++ b/libavcodec/hevcdec.c > @@ -3182,7 +3182,8 @@ static int decode_nal_units(HEVCContext *s, const uint8_t *buf, int length) > return AVERROR(ENOMEM); > memcpy(s->rpu_buf->data, nal->raw_data + 2, nal->raw_size - 2); > > - ret = ff_dovi_rpu_parse(&s->dovi_ctx, nal->data + 2, nal->size - 2); > + ret = ff_dovi_rpu_parse(&s->dovi_ctx, nal->data + 2, nal->size - 2, > + s->avctx->err_recognition); > if (ret < 0) { > av_buffer_unref(&s->rpu_buf); > av_log(s->avctx, AV_LOG_WARNING, "Error parsing DOVI NAL unit.\n"); _______________________________________________ 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".