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

Thierry Foucu tfoucu at gmail.com
Mon Jun 27 20:01:21 CEST 2011


On Sun, Jun 26, 2011 at 12:54 PM, Tobias Diedrich <ranma at tdiedrich.de>wrote:

> 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;
>
>
The other problem is that in libmpdemux/muxer_lavf.c
we do not check the return value of av_write_header in write_header
If we were to check the return value, we will find out that something was
wrong and we will not crash later in av_frac_add


> --
> Tobias                                          PGP:
> http://8ef7ddba.uguu.de
> _______________________________________________
> MPlayer-dev-eng mailing list
> MPlayer-dev-eng at mplayerhq.hu
> https://lists.mplayerhq.hu/mailman/listinfo/mplayer-dev-eng
>


More information about the MPlayer-dev-eng mailing list