From: Niklas Haas <ffmpeg@haasn.xyz>
To: ffmpeg-devel@ffmpeg.org
Cc: quietvoid <tcChlisop0@gmail.com>, Niklas Haas <git@haasn.dev>
Subject: [FFmpeg-devel] [PATCH 4/6] avcodec/dovi_rpu: verify RPU data CRC32
Date: Sat, 23 Mar 2024 18:37:33 +0100
Message-ID: <20240323173735.26224-4-ffmpeg@haasn.xyz> (raw)
In-Reply-To: <20240323173735.26224-1-ffmpeg@haasn.xyz>
From: Niklas Haas <git@haasn.dev>
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.
Co-authored-by: quietvoid <tcChlisop0@gmail.com>
---
libavcodec/av1dec.c | 3 ++-
libavcodec/dovi_rpu.c | 18 ++++++++++++++++--
libavcodec/dovi_rpu.h | 3 ++-
libavcodec/hevcdec.c | 3 ++-
libavcodec/libdav1d.c | 3 ++-
5 files changed, 24 insertions(+), 6 deletions(-)
diff --git a/libavcodec/av1dec.c b/libavcodec/av1dec.c
index 4d074c39087..bff921a12b2 100644
--- a/libavcodec/av1dec.c
+++ b/libavcodec/av1dec.c
@@ -1001,7 +1001,8 @@ static int export_itut_t35(AVCodecContext *avctx, AVFrame *frame,
provider_oriented_code != 0x800)
break;
- ret = ff_dovi_rpu_parse(&s->dovi, gb.buffer, gb.buffer_end - gb.buffer);
+ ret = ff_dovi_rpu_parse(&s->dovi, gb.buffer, gb.buffer_end - gb.buffer,
+ avctx->err_recognition);
if (ret < 0) {
av_log(avctx, AV_LOG_WARNING, "Error parsing DOVI OBU.\n");
break; // ignore
diff --git a/libavcodec/dovi_rpu.c b/libavcodec/dovi_rpu.c
index 24a1cdf39a8..cd54c8716dc 100644
--- a/libavcodec/dovi_rpu.c
+++ b/libavcodec/dovi_rpu.c
@@ -22,6 +22,7 @@
*/
#include "libavutil/buffer.h"
+#include "libavutil/crc.h"
#include "avcodec.h"
#include "dovi_rpu.h"
@@ -197,7 +198,8 @@ static inline unsigned get_variable_bits(GetBitContext *gb, int n)
} \
} 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};
@@ -268,6 +270,19 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size)
rpu_size--;
}
+ if (!rpu_size || rpu[rpu_size - 1] != 0x80)
+ goto fail;
+
+ if (err_recognition & AV_EF_CRCCHECK) {
+ uint32_t crc = av_bswap32(av_crc(av_crc_get_table(AV_CRC_32_IEEE),
+ -1, rpu, rpu_size - 1)); /* exclude 0x80 */
+ if (crc) {
+ av_log(s->logctx, AV_LOG_ERROR, "RPU CRC mismatch: %X\n", crc);
+ if (err_recognition & AV_EF_EXPLODE)
+ goto fail;
+ }
+ }
+
if ((ret = init_get_bits8(gb, rpu, rpu_size)) < 0)
return ret;
@@ -508,7 +523,6 @@ 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 */
return 0;
fail:
diff --git a/libavcodec/dovi_rpu.h b/libavcodec/dovi_rpu.h
index 506974a74bf..f88fbf9b558 100644
--- a/libavcodec/dovi_rpu.h
+++ b/libavcodec/dovi_rpu.h
@@ -79,7 +79,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 76aa6b45882..ebd70eda234 100644
--- a/libavcodec/hevcdec.c
+++ b/libavcodec/hevcdec.c
@@ -3193,7 +3193,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");
diff --git a/libavcodec/libdav1d.c b/libavcodec/libdav1d.c
index 17b0743cf0c..af95e46c343 100644
--- a/libavcodec/libdav1d.c
+++ b/libavcodec/libdav1d.c
@@ -567,7 +567,8 @@ static int libdav1d_receive_frame(AVCodecContext *c, AVFrame *frame)
provider_oriented_code != 0x800)
break;
- res = ff_dovi_rpu_parse(&dav1d->dovi, gb.buffer, gb.buffer_end - gb.buffer);
+ res = ff_dovi_rpu_parse(&dav1d->dovi, gb.buffer, gb.buffer_end - gb.buffer,
+ c->err_recognition);
if (res < 0) {
av_log(c, AV_LOG_WARNING, "Error parsing DOVI OBU.\n");
break; // ignore
--
2.44.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".
next prev parent reply other threads:[~2024-03-23 17:37 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-03-23 17:37 [FFmpeg-devel] [PATCH 1/6] avutil/dovi_meta: add AVDOVIDataMapping.nlq_pivots Niklas Haas
2024-03-23 17:37 ` [FFmpeg-devel] [PATCH 2/6] avutil/dovi_meta: add dolby vision extension blocks Niklas Haas
2024-03-23 17:58 ` Andreas Rheinhardt
2024-03-23 18:08 ` Niklas Haas
2024-03-23 18:45 ` Niklas Haas
2024-03-23 17:37 ` [FFmpeg-devel] [PATCH 3/6] avcodec/dovi_rpu: strip container in separate step Niklas Haas
2024-03-23 18:02 ` Andreas Rheinhardt
2024-03-23 18:06 ` Niklas Haas
2024-03-23 17:37 ` Niklas Haas [this message]
2024-03-23 17:37 ` [FFmpeg-devel] [PATCH 5/6] avcodec/dovi_rpu: add ext_blocks array to DOVIContext Niklas Haas
2024-03-23 17:37 ` [FFmpeg-devel] [PATCH 6/6] avcodec/dovi_rpu: parse extension blocks Niklas Haas
2024-03-23 18:00 ` Andreas Rheinhardt
2024-03-23 18:23 ` Niklas Haas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240323173735.26224-4-ffmpeg@haasn.xyz \
--to=ffmpeg@haasn.xyz \
--cc=ffmpeg-devel@ffmpeg.org \
--cc=git@haasn.dev \
--cc=tcChlisop0@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git