oggdec: check stream index before using it in ogg_get_length()
authorMichael Niedermayer <michaelni@gmx.at>
Sun, 5 Aug 2012 02:41:34 +0000 (04:41 +0200)
committerMichael Niedermayer <michaelni@gmx.at>
Sun, 5 Aug 2012 03:08:15 +0000 (05:08 +0200)
Fixes crash based on a uninitialized array index read.
If the read does not crash then out of array writes based
on the same index might have been triggered afterwards.

Found-by: inferno@chromium.org
Signed-off-by: Michael Niedermayer <michaelni@gmx.at>
libavformat/oggdec.c

index b2d734a..0a46501 100644 (file)
@@ -525,7 +525,9 @@ static int ogg_get_length(AVFormatContext *s)
     ogg_save (s);
     avio_seek (s->pb, s->data_offset, SEEK_SET);
     ogg_reset(s);
+    i = -1;
     while (!ogg_packet(s, &i, NULL, NULL, NULL)) {
+        if(i>=0) {
         int64_t pts = ogg_calc_pts(s, i, NULL);
         if (pts != AV_NOPTS_VALUE && s->streams[i]->start_time == AV_NOPTS_VALUE && !ogg->streams[i].got_start){
             s->streams[i]->duration -= pts;
@@ -535,6 +537,7 @@ static int ogg_get_length(AVFormatContext *s)
             ogg->streams[i].got_start= 1;
             streams_left--;
         }
+        }
             if(streams_left<=0)
                 break;
     }