$OpenBSD: patch-libavformat_oggdec_c,v 1.1 2011/08/03 18:44:07 dcoppa Exp $

- Abort header parsing when encountering a data packet.
- Prevent heap corruption.

--- libavformat/oggdec.c.orig	Sat Jul 30 00:31:23 2011
+++ libavformat/oggdec.c	Sat Jul 30 00:45:30 2011
@@ -376,8 +376,7 @@ ogg_packet (AVFormatContext * s, int *str, int *dstart
 
             // We have reached the first non-header packet in this stream.
             // Unfortunately more header packets may still follow for others,
-            // so we reset this later unless we are done with the headers
-            // for all streams.
+            // but if we continue with header parsing we may lose data packets.
             ogg->headers = 1;
 
             // Update the header state for all streams and
@@ -386,8 +385,6 @@ ogg_packet (AVFormatContext * s, int *str, int *dstart
                 s->data_offset = os->sync_pos;
             for (i = 0; i < ogg->nstreams; i++) {
                 struct ogg_stream *cur_os = ogg->streams + i;
-                if (cur_os->header > 0)
-                    ogg->headers = 0;
 
                 // if we have a partial non-header packet, its start is
                 // obviously at or after the data start
@@ -600,15 +597,15 @@ ogg_read_timestamp (AVFormatContext * s, int stream_in
                     int64_t pos_limit)
 {
     struct ogg *ogg = s->priv_data;
-    struct ogg_stream *os = ogg->streams + stream_index;
     AVIOContext *bc = s->pb;
     int64_t pts = AV_NOPTS_VALUE;
-    int i;
+    int i = -1;
     avio_seek(bc, *pos_arg, SEEK_SET);
     ogg_reset(ogg);
 
     while (avio_tell(bc) < pos_limit && !ogg_packet(s, &i, NULL, NULL, pos_arg)) {
         if (i == stream_index) {
+            struct ogg_stream *os = ogg->streams + stream_index;
             pts = ogg_calc_pts(s, i, NULL);
             if (os->keyframe_seek && !(os->pflags & AV_PKT_FLAG_KEY))
                 pts = AV_NOPTS_VALUE;
@@ -633,6 +630,7 @@ static int ogg_read_seek(AVFormatContext *s, int strea
         os->keyframe_seek = 1;
 
     ret = av_seek_frame_binary(s, stream_index, timestamp, flags);
+    os = ogg->streams + stream_index;
     if (ret < 0)
         os->keyframe_seek = 0;
     return ret;
