[FFmpeg-devel] [PATCH] avformat/hls: check target duration in the playlist

Steven Liu lq at chinaffmpeg.org
Sat May 16 15:11:56 EEST 2020


fix ticket: 8673
reference rfc8216 4.3.3.1 said:
The EXT-X-TARGETDURATION tag is REQUIRED.

in ticket 8673, the EXT-X-TARGETDURATION is incorrect, so hls should
return error.

Signed-off-by: Steven Liu <lq at chinaffmpeg.org>
---
 libavformat/hls.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/libavformat/hls.c b/libavformat/hls.c
index fc45719d1c..962ab78dd7 100644
--- a/libavformat/hls.c
+++ b/libavformat/hls.c
@@ -725,6 +725,7 @@ static int parse_playlist(HLSContext *c, const char *url,
     struct segment **prev_segments = NULL;
     int prev_n_segments = 0;
     int prev_start_seq_no = -1;
+    int have_target_duration = 0;
 
     if (is_http && !in && c->http_persistent && c->playlist_pb) {
         in = c->playlist_pb;
@@ -809,6 +810,7 @@ static int parse_playlist(HLSContext *c, const char *url,
             if (ret < 0)
                 goto fail;
             pls->target_duration = strtoll(ptr, NULL, 10) * AV_TIME_BASE;
+            have_target_duration = 1;
         } else if (av_strstart(line, "#EXT-X-MEDIA-SEQUENCE:", &ptr)) {
             ret = ensure_playlist(c, &pls, url);
             if (ret < 0)
@@ -875,6 +877,11 @@ static int parse_playlist(HLSContext *c, const char *url,
             }
             if (is_segment) {
                 struct segment *seg;
+                if (!have_target_duration) {
+                    ret = AVERROR_INVALIDDATA;
+                    goto fail;
+                }
+
                 ret = ensure_playlist(c, &pls, url);
                 if (ret < 0)
                     goto fail;
-- 
2.25.0





More information about the ffmpeg-devel mailing list