[FFmpeg-devel] [PATCH] Workaround for MPEG-TS crashes

Ivan Schreter schreter
Sun Sep 13 12:00:57 CEST 2009

Hi Baptiste,

several people reported crashes when working with MPEG-TS files. I 
suppose, those files are either really or subtly broken and MPEG-TS 
format handler doesn't handle them gracefully.

With this patch, the crashes in the samples I have seem to be gone:

Index: libavformat/mpegts.c
--- libavformat/mpegts.c        (revision 19829)
+++ libavformat/mpegts.c        (working copy)
@@ -1036,8 +1036,10 @@
                         return AVERROR(ENOMEM);
                     ts->stop_parse = 1;
-                memcpy(pes->buffer+pes->data_index, p, buf_size);
-                pes->data_index += buf_size;
+                if (pes->buffer) {
+                    memcpy(pes->buffer+pes->data_index, p, buf_size);
+                    pes->data_index += buf_size;
+                }
             buf_size = 0;

However, it's IMHO just a workaround and the real root cause of the 
problem should be found. At this time, pes->buffer is NULL, but data for 
PES packet are coming in => crash.

Crashing sample is here: 
Playable sample is here: 

Both samples seem to be seriously broken at the beginning. They 
originated from a HDV-capable camcorder (MPEG-TS containing MPEG-2 video).

Note: With the workaround, the crashing sample doesn't crash anymore, 
but also no video is detected. Therefore I assume just ignoring data if 
PES buffer is NULL is not the correct solution (though, possibly video 
is not detected simply because no healthy video frame was found at the 

Can you please check?

Thanks & regards,


More information about the ffmpeg-devel mailing list