[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;
             break;

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: 
http://dennedy.org/~ddennedy/dvgrab-2009.03.28_19-07-22.m2t
Playable sample is here: 
http://dennedy.org/~ddennedy/dvgrab-2009.03.28_19-06-41.m2t

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 
beginning?).

Can you please check?

Thanks & regards,

Ivan




More information about the ffmpeg-devel mailing list