Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Niklas Haas <ffmpeg@haasn.xyz>
To: ffmpeg-devel@ffmpeg.org
Cc: Niklas Haas <git@haasn.dev>
Subject: [FFmpeg-devel] [PATCH 8/8] avcodec/dovi_rpudec: handle errors consistently
Date: Sun,  9 Jun 2024 17:05:53 +0200
Message-ID: <20240609150553.72865-8-ffmpeg@haasn.xyz> (raw)
In-Reply-To: <20240609150553.72865-1-ffmpeg@haasn.xyz>

From: Niklas Haas <git@haasn.dev>

Only flush state when we started parsing data, otherwise just error out.
Remove the 'fail' label to make this a bit less confusing to read.
---
 libavcodec/dovi_rpudec.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/libavcodec/dovi_rpudec.c b/libavcodec/dovi_rpudec.c
index e947870d45..72e4add618 100644
--- a/libavcodec/dovi_rpudec.c
+++ b/libavcodec/dovi_rpudec.c
@@ -123,7 +123,8 @@ static inline unsigned get_variable_bits(GetBitContext *gb, int n)
         if (VAR < MIN || VAR > MAX) {                                           \
             av_log(s->logctx, AV_LOG_ERROR, "RPU validation failed: "           \
                    #MIN" <= "#VAR" = %d <= "#MAX"\n", (int) VAR);               \
-            goto fail;                                                          \
+            ff_dovi_ctx_unref(s);                                               \
+            return AVERROR_INVALIDDATA;                                         \
         }                                                                       \
     } while (0)
 
@@ -306,7 +307,7 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size,
     uint8_t profile;
 
     if (rpu_size < 5)
-        goto fail;
+        return AVERROR_INVALIDDATA;
 
     /* Container */
     if (s->cfg.dv_profile == 10 /* dav1.10 */) {
@@ -360,7 +361,7 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size,
     }
 
     if (!rpu_size || rpu[rpu_size - 1] != 0x80)
-        goto fail;
+        return AVERROR_INVALIDDATA;
 
     if (err_recognition & AV_EF_CRCCHECK) {
         uint32_t crc = av_bswap32(av_crc(av_crc_get_table(AV_CRC_32_IEEE),
@@ -368,7 +369,7 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size,
         if (crc) {
             av_log(s->logctx, AV_LOG_ERROR, "RPU CRC mismatch: %X\n", crc);
             if (err_recognition & AV_EF_EXPLODE)
-                goto fail;
+                return AVERROR_INVALIDDATA;
         }
     }
 
@@ -439,7 +440,8 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size,
     profile = s->cfg.dv_profile ? s->cfg.dv_profile : ff_dovi_guess_profile_hevc(hdr);
     if (profile == 5 && use_nlq) {
         av_log(s->logctx, AV_LOG_ERROR, "Profile 5 RPUs should not use NLQ\n");
-        goto fail;
+        ff_dovi_ctx_unref(s);
+        return AVERROR_INVALIDDATA;
     }
 
     if (use_prev_vdr_rpu) {
@@ -453,7 +455,8 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size,
              * out as this corner case is not hit in practice */
             av_log(s->logctx, AV_LOG_ERROR, "Unknown previous RPU ID: %u\n",
                    prev_vdr_rpu_id);
-            goto fail;
+            ff_dovi_ctx_unref(s);
+            return AVERROR_INVALIDDATA;
         }
         s->mapping = s->vdr[prev_vdr_rpu_id];
     } else {
@@ -462,8 +465,10 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size,
         VALIDATE(vdr_rpu_id, 0, DOVI_MAX_DM_ID);
         if (!s->vdr[vdr_rpu_id]) {
             s->vdr[vdr_rpu_id] = ff_refstruct_allocz(sizeof(AVDOVIDataMapping));
-            if (!s->vdr[vdr_rpu_id])
+            if (!s->vdr[vdr_rpu_id]) {
+                ff_dovi_ctx_unref(s);
                 return AVERROR(ENOMEM);
+            }
         }
 
         s->mapping = mapping = s->vdr[vdr_rpu_id];
@@ -635,8 +640,4 @@ int ff_dovi_rpu_parse(DOVIContext *s, const uint8_t *rpu, size_t rpu_size,
     }
 
     return 0;
-
-fail:
-    ff_dovi_ctx_unref(s); /* don't leak potentially invalid state */
-    return AVERROR_INVALIDDATA;
 }
-- 
2.45.1

_______________________________________________
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".

  parent reply	other threads:[~2024-06-09 15:06 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-06-09 15:05 [FFmpeg-devel] [PATCH 1/8] avdovi/dovi_rpudec: handle prev_vdr_rpu_id failures Niklas Haas
2024-06-09 15:05 ` [FFmpeg-devel] [PATCH 2/8] avcodec/dovi_rpu: properly handle vdr_dm_metadata_present Niklas Haas
2024-06-09 15:05 ` [FFmpeg-devel] [PATCH 3/8] avcodec/dovi_rpu: fix dm_metadata_id handling Niklas Haas
2024-06-09 15:05 ` [FFmpeg-devel] [PATCH 4/8] avcodec/dovi_rpudec: simplify vdr handling (cosmetic) Niklas Haas
2024-06-09 15:05 ` [FFmpeg-devel] [PATCH 5/8] avcodec/dovi_rpu: simplify vdr type Niklas Haas
2024-06-09 15:05 ` [FFmpeg-devel] [PATCH 6/8] avcodec/dovi_rpu: guard ext blocks by dm_metadata_present Niklas Haas
2024-06-09 15:05 ` [FFmpeg-devel] [PATCH 7/8] avcodec/dovi_rpudec: reject reserved_zero_3bits != 0 Niklas Haas
2024-06-09 15:05 ` Niklas Haas [this message]
2024-06-14 11:41 ` [FFmpeg-devel] [PATCH 1/8] avdovi/dovi_rpudec: handle prev_vdr_rpu_id failures 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=20240609150553.72865-8-ffmpeg@haasn.xyz \
    --to=ffmpeg@haasn.xyz \
    --cc=ffmpeg-devel@ffmpeg.org \
    --cc=git@haasn.dev \
    /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