[MPlayer-dev-eng] [PATCH] Ignore 0-len packets for muxer prebuffering

Tobias Diedrich ranma at tdiedrich.de
Sun Jun 26 21:54:06 CEST 2011


Tobias Diedrich wrote:
> Reimar Döffinger wrote:
> > Thanks for taking care of it.
> > 
> > On Thu, Jun 23, 2011 at 11:26:13PM +0200, Tobias Diedrich wrote:
> > > This fixes an issue where the libavformat muxer could not determine the
> > > image dimensions while writing the header and subsequently crash with
> > > a divison by zero, which is caused by calling muxer_write_header too early.
> > 
> > Can you pinpoint the crash in libavformat? Because IMHO that is a real,
> > even somewhat serious bug in libavformat still, even if MPlayer didn't
> > feed it quite correct data.
> 
> Writing header...
> [avi @ 0xa900c0]dimensions not set
> 
> Program received signal SIGFPE, Arithmetic exception.
> 0x00000000006645c2 in av_frac_add (s=0x1485630, st=0x168dcb0, 
>     pkt=0x7fffffffdbb0) at libavformat/utils.c:114
> 114             f->val += num / den;
> (gdb)

diff --git a/libavformat/avienc.c b/libavformat/avienc.c
index 8a53bb5..c82071a 100644
--- a/libavformat/avienc.c
+++ b/libavformat/avienc.c
@@ -519,6 +519,11 @@ static int avi_write_packet(AVFormatContext *s, AVPacket *pkt)
     AVCodecContext *enc= s->streams[stream_index]->codec;
     int size= pkt->size;
 
+    if (!avist) {
+        av_log(s, AV_LOG_FATAL, "avist is NULL for stream_index %d!\n", stream_index);
+        return 0;
+    }
+
 //    av_log(s, AV_LOG_DEBUG, "%"PRId64" %d %d\n", pkt->dts, avist->packet_count, stream_index);
     while(enc->block_align==0 && pkt->dts != AV_NOPTS_VALUE && pkt->dts > avist->packet_count){
         AVPacket empty_packet;
diff --git a/libavformat/utils.c b/libavformat/utils.c
index e0a5455..a255757 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -81,6 +81,8 @@ const char *avformat_license(void)
  */
 static void av_frac_init(AVFrac *f, int64_t val, int64_t num, int64_t den)
 {
+    if (den <= 0)
+        return;
     num += (den >> 1);
     if (num >= den) {
         val += num / den;
@@ -103,6 +105,8 @@ static void av_frac_add(AVFrac *f, int64_t incr)
 
     num = f->num + incr;
     den = f->den;
+    if (den <= 0)
+        return;
     if (num < 0) {
         f->val += num / den;
         num = num % den;

-- 
Tobias						PGP: http://8ef7ddba.uguu.de


More information about the MPlayer-dev-eng mailing list