[FFmpeg-cvslog] avcodec/dovi_rpudec: handle errors consistently

Niklas Haas git at videolan.org
Tue Jun 18 22:19:04 EEST 2024


ffmpeg | branch: master | Niklas Haas <git at haasn.dev> | Sun Jun  9 17:02:51 2024 +0200| [90579fbb907fbfda18b7cdac44c08aaf09c6ca09] | committer: Niklas Haas

avcodec/dovi_rpudec: handle errors consistently

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.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=90579fbb907fbfda18b7cdac44c08aaf09c6ca09
---

 libavcodec/dovi_rpudec.c | 26 ++++++++++++--------------
 1 file changed, 12 insertions(+), 14 deletions(-)

diff --git a/libavcodec/dovi_rpudec.c b/libavcodec/dovi_rpudec.c
index 0f76dbb706..cae4dc4c3c 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)
 
@@ -173,9 +174,6 @@ static int parse_ext_v1(DOVIContext *s, GetBitContext *gb, AVDOVIDmData *dm)
     }
 
     return 0;
-
-fail:
-    return AVERROR_INVALIDDATA;
 }
 
 static AVCIExy get_cie_xy(GetBitContext *gb)
@@ -318,7 +316,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 */) {
@@ -372,7 +370,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),
@@ -380,7 +378,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;
         }
     }
 
@@ -451,7 +449,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) {
@@ -465,7 +464,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 {
@@ -474,8 +474,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];
@@ -647,8 +649,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;
 }



More information about the ffmpeg-cvslog mailing list