[MPlayer-dev-eng] [PATCH] Fix segfault with -chapter

Alexander Strasser eclipse7 at gmx.net
Fri Nov 8 10:33:30 CET 2013


Hi Arne,

  thanks for submitting a patch for this problem and having it tested
by another party already! (I found out about that on #mplayer IRC.)

On 2013-11-05 21:21 +0100, Arne Bochem wrote:
> When running:
> 	mplayer -chapter 2 foo.mkv
> (ASS enabled.)
> 
> The following crash occurs:
> 
> Program received signal SIGSEGV, Segmentation fault.
> 0x00005555556b573c in seek (mpctx=mpctx at entry=0x555556506ae0, amount=..., style=style at entry=1) at mplayer.c:2749
> 2749	    if (ass_enabled && mpctx->d_sub->sh && ((sh_sub_t *)mpctx->d_sub->sh)->ass_track)
> (gdb) bt
> #0  0x00005555556b573c in seek (mpctx=mpctx at entry=0x555556506ae0, amount=..., style=style at entry=1) at mplayer.c:2749
> #1  0x00005555556a8322 in main (argc=4, argv=0x7fffffffdfe8) at mplayer.c:3429
> (gdb) print mpctx->d_sub
> $1 = (demux_stream_t *) 0x0
> 
> Fixed by moving -chapter seeking below the place where mpctx->d_sub is
> initialized.

  I have an alternative fix attached. If nobody is of the opinion that
your patch is superior I would prefer to commit mine, as I consider it
slightly less risky. What do you think, Arne?

  Anyway something should be done soon.

  Alexander

> Index: mplayer.c
> ===================================================================
> --- mplayer.c	(revision 36500)
> +++ mplayer.c	(working copy)
> @@ -3423,11 +3423,6 @@
>  
>      if (!mpctx->demuxer)
>          goto goto_next_file;
> -    if (dvd_chapter > 1) {
> -        float pts;
> -        if (demuxer_seek_chapter(mpctx->demuxer, dvd_chapter - 1, 1, &pts, NULL, NULL) >= 0 && pts > -1.0)
> -            seek(mpctx, pts, SEEK_ABSOLUTE);
> -    }
>  
>      initialized_flags |= INITIALIZED_DEMUXER;
>  
> @@ -3450,6 +3445,12 @@
>      mpctx->d_video = mpctx->demuxer->video;
>      mpctx->d_sub   = mpctx->demuxer->sub;
>  
> +    if (dvd_chapter > 1) {
> +        float pts;
> +        if (demuxer_seek_chapter(mpctx->demuxer, dvd_chapter - 1, 1, &pts, NULL, NULL) >= 0 && pts > -1.0)
> +            seek(mpctx, pts, SEEK_ABSOLUTE);
> +    }
> +
>      if (ts_prog) {
>          int tmp = ts_prog;
>          mp_property_do("switch_program", M_PROPERTY_SET, &tmp, mpctx);
-------------- next part --------------
From f55ac00d914800d564332bcbc789e9a0be7fae6e Mon Sep 17 00:00:00 2001
Message-Id: <f55ac00d914800d564332bcbc789e9a0be7fae6e.1383902711.git.eclipse7 at gmx.net>
From: Alexander Strasser <eclipse7 at gmx.net>
Date: Fri, 8 Nov 2013 10:04:45 +0100
Subject: [PATCH] mplayer: Fix a crash seeking with -chapter and -ass

When seeking to chapter on startup the mpctx->d_sub member
is not yet initialized. Do not access it in that case.

The commit r31293 that introduced that code explains that
it is for handling backward seeking correctly. So it should
not be needed on startup forward seek situation.

Signed-off-by: Alexander Strasser <eclipse7 at gmx.net>
---
 mplayer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/mplayer.c b/mplayer.c
index 3869d3a..c16a3c7 100644
--- a/mplayer.c
+++ b/mplayer.c
@@ -2746,7 +2746,7 @@ static int seek(MPContext *mpctx, double amount, int style)
     }
 
 #ifdef CONFIG_ASS
-    if (ass_enabled && mpctx->d_sub->sh && ((sh_sub_t *)mpctx->d_sub->sh)->ass_track)
+    if (ass_enabled && mpctx->d_sub && mpctx->d_sub->sh && ((sh_sub_t *)mpctx->d_sub->sh)->ass_track)
         ass_flush_events(((sh_sub_t *)mpctx->d_sub->sh)->ass_track);
 #endif
 
-- 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/mplayer-dev-eng/attachments/20131108/81f3b8cb/attachment.asc>


More information about the MPlayer-dev-eng mailing list