[MPlayer-dev-eng] [PATCH 1/3] Fix segfault when mplayer -v -v -v is ran on some large MOV files
Petr Baudis
pasky at ucw.cz
Wed May 24 02:58:31 CEST 2006
mplayer -v -v -v on a MOV file with generic tracks will dump them to files
by loading them all to memory first and then writing them at once - that's
not a stellar way how to do it, but it's -v -v -v and only in few special
cases so it doesn't matter much.
The trouble is that the buffer is allocated on stack, which is a bad idea
since the generic track can be pretty big (interesting case is e.g. generic
track containing a MPEG stream, that can be very easily tens or hundreds
of megs). mplayer will just segfault in that case.
This patch changes the code to malloc() the buffer instead.
---
libmpdemux/demux_mov.c | 7 +++++--
1 files changed, 5 insertions(+), 2 deletions(-)
diff --git a/libmpdemux/demux_mov.c b/libmpdemux/demux_mov.c
index 9835f80..078e8e7 100644
--- a/libmpdemux/demux_mov.c
+++ b/libmpdemux/demux_mov.c
@@ -1836,11 +1836,12 @@ #if 1
for (i=0; i<trak->samples_size; i++)
{
int len=trak->samples[i].size;
- char buf[len];
+ char *buf = malloc(len);
stream_seek(demuxer->stream, trak->samples[i].pos);
snprintf(name, 20, "t%02d-s%03d.%s", t_no,i,
(trak->media_handler==MOV_FOURCC('f','l','s','h')) ?
"swf":"dump");
+ mp_msg(MSGT_DEMUX, MSGL_INFO, "MOV: Saving sample %d to file %s ...\n",i,name);
fd = open(name, O_CREAT|O_WRONLY);
// { int j;
// for(j=0;j<trak->stdata_len-3; j++)
@@ -1855,7 +1856,7 @@ #ifdef HAVE_ZLIB
// unzip:
z_stream zstrm;
int zret;
- char buf2[newlen];
+ char *buf2 = malloc(newlen);
len-=4;
stream_read(demuxer->stream, buf, len);
@@ -1874,6 +1875,7 @@ #ifdef HAVE_ZLIB
mp_msg(MSGT_DEMUX, MSGL_WARN, "Warning! unzipped frame size differs hdr: %d zlib: %ld\n",newlen,zstrm.total_out);
write(fd, buf2, newlen);
+ free(buf2);
} else {
#else
len-=4;
@@ -1885,6 +1887,7 @@ #endif
write(fd, buf, len);
}
close(fd);
+ free(buf);
}
}
}
More information about the MPlayer-dev-eng
mailing list