---
 libavformat/asfdec.c | 27 +++++++++++++++------------
 1 file changed, 15 insertions(+), 12 deletions(-)

diff --git a/libavformat/asfdec.c b/libavformat/asfdec.c
index 7af3728..24dde87 100644
--- a/libavformat/asfdec.c
+++ b/libavformat/asfdec.c
@@ -1633,25 +1633,21 @@ static int asf_read_header(AVFormatContext *s)
     avio_skip(pb, 6); // skip number of header objects and 2 reserved bytes
     asf->data_reached = 0;
 
-    /* 1  is here instead of pb->eof_reached because (when not streaming), 
Data are skipped
-     * for the first time,
-     * Index object is processed and got eof and then seeking back to the Data 
is performed.
+    /* Data are skipped for the first time, Index object is processed,
+     * EOF is reached and then seeking back to the Data is performed.
      */
-    while (1) {
+    while (!pb->eof_reached && !asf->data_reached) {
         // for the cases when object size is invalid
         if (avio_tell(pb) == asf->offset) {
-            if (asf->data_reached)
-                avio_seek(pb, asf->first_packet_offset, SEEK_SET);
+            ret = AVERROR_INVALIDDATA;
             break;
         }
+
         asf->offset = avio_tell(pb);
-        if ((ret = ff_get_guid(pb, &guid)) < 0) {
-            if (ret == AVERROR_EOF && asf->data_reached) {
-                avio_seek(pb, asf->first_packet_offset, SEEK_SET);
+        if ((ret = ff_get_guid(pb, &guid)) < 0)
+            if (ret == AVERROR_EOF && asf->data_reached)
                 break;
-            } else
-                return ret;
-        }
+
         g = find_guid(guid);
         if (g) {
             asf->unknown_offset = asf->offset;
@@ -1666,6 +1662,13 @@ static int asf_read_header(AVFormatContext *s)
             break;
     }
 
+    if (pb->seekable) {
+        if (asf->data_reached)
+            avio_seek(pb, asf->first_packet_offset, SEEK_SET);
+        else
+            return AVERROR_INVALIDDATA;
+    }
+
     for (i = 0; i < asf->nb_streams; i++) {
         const char *rfc1766 = asf->asf_sd[asf->asf_st[i]->lang_idx].langs;
         AVStream *st        = s->streams[asf->asf_st[i]->index];
-- 
2.0.1

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to