[Ffmpeg-devel] [PATCH] fix ffmpeg crash when thread_count is zero

Limin Wang lance.lmwang
Wed Feb 28 04:31:21 CET 2007


Hi,

I have figured out the root cause of the crash, please review the
attached patch. It's a corner case for some part of context weren't
initialized in case thread_count is zero.


Thanks,
Limin
-------------- next part --------------
Index: libavcodec/mpegvideo.c
===================================================================
--- libavcodec/mpegvideo.c	(revision 8146)
+++ libavcodec/mpegvideo.c	(working copy)
@@ -825,7 +825,12 @@
         memcpy(s->thread_context[i], s, sizeof(MpegEncContext));
     }
 
-    for(i=0; i<s->avctx->thread_count; i++){
+    if(init_duplicate_context(s->thread_context[0], s) < 0)
+        goto fail;
+    s->thread_context[0]->start_mb_y= 0;
+    s->thread_context[0]->end_mb_y  = s->mb_height;
+
+    for(i=1; i<s->avctx->thread_count; i++){
         if(init_duplicate_context(s->thread_context[i], s) < 0)
            goto fail;
         s->thread_context[i]->start_mb_y= (s->mb_height*(i  ) + s->avctx->thread_count/2) / s->avctx->thread_count;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 481 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20070228/edb62a54/attachment.pgp>



More information about the ffmpeg-devel mailing list