[FFmpeg-cvslog] avformat/mov: Factorize sanity check out

Michael Niedermayer git at videolan.org
Thu Jan 23 03:14:31 EET 2025


ffmpeg | branch: release/7.1 | Michael Niedermayer <michael at niedermayer.cc> | Thu Jan  9 00:02:35 2025 +0100| [41f805228415c51a65b533de8e7f2fa42b24f8ed] | committer: Michael Niedermayer

avformat/mov: Factorize sanity check out

Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>
(cherry picked from commit 16b3d3e3ebb9ff7b00c0fd14b0167779ada87f86)
Signed-off-by: Michael Niedermayer <michael at niedermayer.cc>

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

 libavformat/mov.c | 34 +++++++++++++++++++++-------------
 1 file changed, 21 insertions(+), 13 deletions(-)

diff --git a/libavformat/mov.c b/libavformat/mov.c
index ff32d4160e..6918a6e045 100644
--- a/libavformat/mov.c
+++ b/libavformat/mov.c
@@ -5021,6 +5021,24 @@ static int mov_update_iamf_streams(MOVContext *c, const AVStream *st)
 }
 #endif
 
+static int sanity_checks(void *log_obj, MOVStreamContext *sc, int index)
+{
+    if ((sc->chunk_count && (!sc->stts_count || !sc->stsc_count ||
+                            (!sc->sample_size && !sc->sample_count))) ||
+        (!sc->chunk_count && sc->sample_count)) {
+        av_log(log_obj, AV_LOG_ERROR, "stream %d, missing mandatory atoms, broken header\n",
+               index);
+        return 1;
+    }
+
+    if (sc->stsc_count && sc->stsc_data[ sc->stsc_count - 1 ].first > sc->chunk_count) {
+        av_log(log_obj, AV_LOG_ERROR, "stream %d, contradictionary STSC and STCO\n",
+               index);
+        return 2;
+    }
+    return 0;
+}
+
 static int mov_read_trak(MOVContext *c, AVIOContext *pb, MOVAtom atom)
 {
     AVStream *st;
@@ -5053,19 +5071,9 @@ static int mov_read_trak(MOVContext *c, AVIOContext *pb, MOVAtom atom)
         av_freep(&sc->stsc_data);
     }
 
-    /* sanity checks */
-    if ((sc->chunk_count && (!sc->stts_count || !sc->stsc_count ||
-                            (!sc->sample_size && !sc->sample_count))) ||
-        (!sc->chunk_count && sc->sample_count)) {
-        av_log(c->fc, AV_LOG_ERROR, "stream %d, missing mandatory atoms, broken header\n",
-               st->index);
-        return 0;
-    }
-    if (sc->stsc_count && sc->stsc_data[ sc->stsc_count - 1 ].first > sc->chunk_count) {
-        av_log(c->fc, AV_LOG_ERROR, "stream %d, contradictionary STSC and STCO\n",
-               st->index);
-        return AVERROR_INVALIDDATA;
-    }
+    ret = sanity_checks(c->fc, sc, st->index);
+    if (ret)
+        return ret > 1 ? AVERROR_INVALIDDATA : 0;
 
     fix_timescale(c, sc);
 



More information about the ffmpeg-cvslog mailing list