avformat/gxfenc: Check timecode and propagate error
authorMichael Niedermayer <michael@niedermayer.cc>
Tue, 19 May 2026 14:47:46 +0000 (16:47 +0200)
committerMichael Niedermayer <michael@niedermayer.cc>
Sat, 13 Jun 2026 17:30:45 +0000 (19:30 +0200)
Fixes: ./ffmpeg   -f lavfi -i testsrc=duration=0.1:size=720x480:rate=30   -c:v mpeg2video -frames:v 1   -metadata timecode="999999999:00:00:00"   -f gxf output.gxf

Found-by: jiale yao
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
(cherry picked from commit 0ea090e09f1e0d0407e961284ee9de8c31b8c1b1)
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
libavformat/gxfenc.c

index 6d4df894f63087dc7800651a7b40897c5b4ca4bb..4955e0fb366dbe588f0e6e6ad26432a804626f71 100644 (file)
@@ -685,9 +685,12 @@ static int gxf_init_timecode(AVFormatContext *s, GXFTimecode *tc, const char *tc
     if (sscanf(tcstr, "%d:%d:%d%c%d", &tc->hh, &tc->mm, &tc->ss, &c, &tc->ff) != 5) {
         av_log(s, AV_LOG_ERROR, "unable to parse timecode, "
                                 "syntax: hh:mm:ss[:;.]ff\n");
-        return -1;
+        return AVERROR(EINVAL);
     }
 
+    if (tc->hh > 31U  || tc->mm > 255U || tc->ss > 255U || tc->ff > (255U >> (fields == 2)))
+        return AVERROR(EINVAL);
+
     tc->color = 0;
     tc->drop = c != ':';
 
@@ -819,8 +822,11 @@ static int gxf_write_header(AVFormatContext *s)
         sc->order = s->nb_streams - st->index;
     }
 
-    if (tcr && vsc)
-        gxf_init_timecode(s, &gxf->tc, tcr->value, vsc->fields);
+    if (tcr && vsc) {
+        ret = gxf_init_timecode(s, &gxf->tc, tcr->value, vsc->fields);
+        if (ret < 0)
+            return ret;
+    }
 
     gxf_init_timecode_track(&gxf->timecode_track, vsc);
     gxf->flags |= 0x200000; // time code track is non-drop frame