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 A099346D30 for ; Wed, 9 Aug 2023 15:02:24 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CE9C568C766; Wed, 9 Aug 2023 18:02:21 +0300 (EEST) Received: from mail-qk1-f174.google.com (mail-qk1-f174.google.com [209.85.222.174]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2A98F68C72F for ; Wed, 9 Aug 2023 18:02:16 +0300 (EEST) Received: by mail-qk1-f174.google.com with SMTP id af79cd13be357-7653bd3ff2fso631839185a.3 for ; Wed, 09 Aug 2023 08:02:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691593334; x=1692198134; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=4vu+5SLLvhS7hklU2OIrtLLanBsxAp5P/FBnT5zNqVE=; b=oGNhIsRZhXKnKoEspg8uOXWrgzQAYgxRV14XLGo6KnRmSnnad8rrWUcQKzYnQXemww WXfu8KDtoxsL/RnKOZ0XhNoJhKKYTM/It1FA2mLWcNIxYSkuk4drwqbWVL33bZ+C4cJ0 hgtJGPC0iN1v8I2k3rD/zFfLxKnSks2Fpul6AipdqcVYIavjF9Fx7MldssojQeTwsQEH o7HHHdhAxDVfoNOefJVYgw+kEHQDqc54AtdlkX2ngXHf9oq+LuYNlv/9kjGvs8QjNkAa qasKItMUnA9vWMBVXoXpEyh05CZo/u7bh2wxTCnNuF8PPJIa2ofs4YV9wDspqdKAetqB u+qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691593334; x=1692198134; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=4vu+5SLLvhS7hklU2OIrtLLanBsxAp5P/FBnT5zNqVE=; b=STAwHsEzXkgw8RwXlQVGMqCooHsgRmbBWJsFypuU8RrFIUdOZ9BVG9DL6gWG/F9hEw WejtMjTB4zYvBB/A5+kZscPLtGsLcsXAh+dUHueGR/4cb3i4Drvf+6kJuMbA7cxgqmrv jh/k/nQkdYzWLYqutEdhpg81iRit8YQ0gqsatkghH3SyFn9uIFqbpS/qrGEH7d3e85X8 s0sdgxBAYUa4ilsdb26ihglmpsoBdT28TkfUa4f3YVEzxigf38q7QEW15dhtKhi0obC3 LrVFgJXtllG1Jgh8S9QAb3h682Qp27+VEupc9dfaX0fkUbNOTdhG9dN5j181hAFg+y74 Sfxw== X-Gm-Message-State: AOJu0Yxa2OVT1yC7ICeMOScPX2YwmJTZjfHlL0uKkICSqrRV2Aras8dz eSw1pa9n92RUq1qGghksxWxJFZ0ONw8MjA== X-Google-Smtp-Source: AGHT+IHPZSt22nVo+4CNBbWRCDZ1Fiwb6iJc9PPD9aX3dlEmuqeSLL7/B1sjv00IVmQAMxlPTLHlSQ== X-Received: by 2002:a05:620a:170c:b0:76d:2784:6761 with SMTP id az12-20020a05620a170c00b0076d27846761mr1013683qkb.71.1691593334095; Wed, 09 Aug 2023 08:02:14 -0700 (PDT) Received: from nark.. ([146.70.198.174]) by smtp.gmail.com with ESMTPSA id c28-20020a05620a135c00b007682697dcb0sm4024479qkl.76.2023.08.09.08.02.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Aug 2023 08:02:13 -0700 (PDT) From: quietvoid X-Google-Original-From: quietvoid To: ffmpeg-devel@ffmpeg.org Date: Wed, 9 Aug 2023 11:01:55 -0400 Message-ID: <20230809150155.96-1-tcChlisop0@gmail.com> X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH] 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 Cc: quietvoid 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: The Dolby Vision RPU contains a CRC32 to validate the payload against. It must be an identical match for the metadata to be used. The implementation is CRC32/MPEG-2. Signed-off-by: quietvoid --- libavcodec/dovi_rpu.c | 37 +++++++++++++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/libavcodec/dovi_rpu.c b/libavcodec/dovi_rpu.c index dd38936552..00f811e3a6 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" @@ -198,6 +199,9 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size) 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 +209,21 @@ 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 +458,22 @@ 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); + + rpu_data_crc32 = get_bits_long(gb, 32); + + /* Verify CRC32, the 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, + "Invalid RPU CRC32: Received %"PRIu32", expected %"PRIu32"\n", + computed_crc32, rpu_data_crc32); + goto fail; + } + return 0; fail: -- 2.41.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".