From 6d0c6f74bce43810c2c8a7ca01de5e1f0e7da333 Mon Sep 17 00:00:00 2001
Date: Mon, 18 Feb 2013 11:27:59 +0000
Subject: [PATCH] matroska-Check-return-value-of-avio_seek-and-avoid-m

---
 libavformat/matroskadec.c |   19 ++++++++++++-------
 1 file changed, 12 insertions(+), 7 deletions(-)

diff --git a/libavformat/matroskadec.c b/libavformat/matroskadec.c
index 87c4a39..d066186 100644
--- a/libavformat/matroskadec.c
+++ b/libavformat/matroskadec.c
@@ -2386,7 +2386,8 @@ static int matroska_read_seek(AVFormatContext *s, int stream_index,
     timestamp = FFMAX(timestamp, st->index_entries[0].timestamp);
 
     if ((index = av_index_search_timestamp(st, timestamp, flags)) < 0) {
-        avio_seek(s->pb, st->index_entries[st->nb_index_entries-1].pos, SEEK_SET);
+        if (avio_seek(s->pb, st->index_entries[st->nb_index_entries-1].pos, SEEK_SET) < 0)
+            return -1;
         matroska->current_id = 0;
         while ((index = av_index_search_timestamp(st, timestamp, flags)) < 0) {
             matroska_clear_queue(matroska);
@@ -2395,16 +2396,11 @@ static int matroska_read_seek(AVFormatContext *s, int stream_index,
         }
     }
 
-    matroska_clear_queue(matroska);
     if (index < 0 || (matroska->cues_parsing_deferred < 0 && index == st->nb_index_entries - 1))
         goto err;
 
     index_min = index;
     for (i=0; i < matroska->tracks.nb_elem; i++) {
-        tracks[i].audio.pkt_cnt = 0;
-        tracks[i].audio.sub_packet_cnt = 0;
-        tracks[i].audio.buf_timecode = AV_NOPTS_VALUE;
-        tracks[i].end_timecode = 0;
         if (tracks[i].type == MATROSKA_TRACK_TYPE_SUBTITLE
             && tracks[i].stream->discard != AVDISCARD_ALL) {
             index_sub = av_index_search_timestamp(tracks[i].stream, st->index_entries[index].timestamp, AVSEEK_FLAG_BACKWARD);
@@ -2415,7 +2411,16 @@ static int matroska_read_seek(AVFormatContext *s, int stream_index,
         }
     }
 
-    avio_seek(s->pb, st->index_entries[index_min].pos, SEEK_SET);
+    if (avio_seek(s->pb, st->index_entries[index_min].pos, SEEK_SET) < 0)
+        return -1;
+
+    matroska_clear_queue(matroska);
+    for (i=0; i < matroska->tracks.nb_elem; i++) {
+        tracks[i].audio.pkt_cnt = 0;
+        tracks[i].audio.sub_packet_cnt = 0;
+        tracks[i].audio.buf_timecode = AV_NOPTS_VALUE;
+        tracks[i].end_timecode = 0;
+    }
     matroska->current_id = 0;
     st->skip_to_keyframe =
     matroska->skip_to_keyframe = !(flags & AVSEEK_FLAG_ANY);
-- 
1.7.10.4

