From: Xiaohan Wang Date: Thu, 6 Nov 2014 20:59:54 +0000 (-0800) Subject: Fix read-after-free in matroska_read_seek(). X-Git-Tag: android-x86-4.4-r3^2~40 X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=0b25a4d253baa8f6b786b04b4417824857e2eb73;p=android-x86%2Fexternal-ffmpeg.git Fix read-after-free in matroska_read_seek(). In matroska_read_seek(), |tracks| is assigned at the begining of the function. However, functions like matroska_parse_cues() could reallocate the tracks so that |tracks| can get invalidated. This CL assigns |tracks| only before we use it so that it won't be invalidated. BUG=427266 TEST=Test case in associated bug passes now. Change-Id: I9c7065fe8f4311ca846076281df2282d190ed344 Signed-off-by: Michael Niedermayer (cherry picked from commit 33301f001747d7a542073c634cc81da5eff051cf) Conflicts: libavformat/matroskadec.c --- diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c index 99baa08e7e..e52245dd90 100644 --- a/libavformat/matroskadec.c +++ b/libavformat/matroskadec.c @@ -2797,7 +2797,7 @@ static int matroska_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp, int flags) { MatroskaDemuxContext *matroska = s->priv_data; - MatroskaTrack *tracks = matroska->tracks.elem; + MatroskaTrack *tracks = NULL; AVStream *st = s->streams[stream_index]; int i, index, index_sub, index_min; @@ -2826,6 +2826,7 @@ static int matroska_read_seek(AVFormatContext *s, int stream_index, goto err; index_min = index; + tracks = matroska->tracks.elem; for (i=0; i < matroska->tracks.nb_elem; i++) { tracks[i].audio.pkt_cnt = 0; tracks[i].audio.sub_packet_cnt = 0;