[FFmpeg-devel] [PATCH] Fixed corrupt segment video files when using hls_init_time option.

Laszlo Kovacs atomantinator at gmail.com
Fri Mar 29 01:48:51 EET 2019


The problem is an integer overflow on "after_init_list_dur" variable.
It happens about 30-40 minutes after starts hls streaming but strongly depends on other options like "start_number" or "hls_list_size".
VOD or EVENT hls playlist types are not affected by this bug.

(P.S. I hope this text will be the body and not the subject :) )
---
 libavformat/hlsenc.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/libavformat/hlsenc.c b/libavformat/hlsenc.c
index 5f9a200c6e..2e8bcab571 100644
--- a/libavformat/hlsenc.c
+++ b/libavformat/hlsenc.c
@@ -2195,8 +2195,9 @@ static int hls_write_packet(AVFormatContext *s, AVPacket *pkt)
 
     if (vs->sequence - vs->nb_entries > hls->start_sequence && hls->init_time > 0) {
         /* reset end_pts, hls->recording_time at end of the init hls list */
-        int init_list_dur = hls->init_time * vs->nb_entries * AV_TIME_BASE;
-        int after_init_list_dur = (vs->sequence - hls->start_sequence - vs->nb_entries ) * (hls->time * AV_TIME_BASE);
+        int64_t init_list_dur = hls->init_time * vs->nb_entries * AV_TIME_BASE;
+        int64_t after_init_list_dur = hls->time * AV_TIME_BASE;
+        after_init_list_dur *= vs->sequence - hls->start_sequence - vs->nb_entries;
         hls->recording_time = hls->time * AV_TIME_BASE;
         end_pts = init_list_dur + after_init_list_dur ;
     }
-- 
2.17.1



More information about the ffmpeg-devel mailing list