[vlc-commits] httplive: fix stream detection

Rafaël Carré git at videolan.org
Mon Mar 5 17:34:28 CET 2012


vlc | branch: master | Rafaël Carré <funman at videolan.org> | Mon Mar  5 11:15:27 2012 -0500| [74f02326dc168aa632fe68c29951cf3824dfce06] | committer: Rafaël Carré

httplive: fix stream detection

Using str*() on a bytestream is a bad idea.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=74f02326dc168aa632fe68c29951cf3824dfce06
---

 modules/stream_filter/httplive.c |   66 ++++++++++++++++++++++---------------
 1 files changed, 39 insertions(+), 27 deletions(-)

diff --git a/modules/stream_filter/httplive.c b/modules/stream_filter/httplive.c
index 7e8c558..71730f4 100644
--- a/modules/stream_filter/httplive.c
+++ b/modules/stream_filter/httplive.c
@@ -165,45 +165,57 @@ static void segment_Free(segment_t *segment);
 /****************************************************************************
  *
  ****************************************************************************/
-static const char *const ext[] = {
-    "#EXT-X-TARGETDURATION",
-    "#EXT-X-MEDIA-SEQUENCE",
-    "#EXT-X-KEY",
-    "#EXT-X-ALLOW-CACHE",
-    "#EXT-X-ENDLIST",
-    "#EXT-X-STREAM-INF",
-    "#EXT-X-DISCONTINUITY",
-    "#EXT-X-VERSION"
-};
-
 static bool isHTTPLiveStreaming(stream_t *s)
 {
-    const uint8_t *peek, *peek_end;
+    const uint8_t *peek;
 
-    int64_t i_size = stream_Peek(s->p_source, &peek, 46);
-    if (i_size < 1)
+    int size = stream_Peek(s->p_source, &peek, 46);
+    if (size < 7)
         return false;
 
-    if (strncasecmp((const char*)peek, "#EXTM3U", 7) != 0)
+    if (memcmp(peek, "#EXTM3U", 7) != 0)
         return false;
 
+    peek += 7;
+    size -= 7;
+
     /* Parse stream and search for
      * EXT-X-TARGETDURATION or EXT-X-STREAM-INF tag, see
      * http://tools.ietf.org/html/draft-pantos-http-live-streaming-04#page-8 */
-    peek_end = peek + i_size;
-    while(peek <= peek_end)
-    {
-        if (*peek == '#')
+    while (size--)
+    {
+        static const char *const ext[] = {
+            "TARGETDURATION",
+            "MEDIA-SEQUENCE",
+            "KEY",
+            "ALLOW-CACHE",
+            "ENDLIST",
+            "STREAM-INF",
+            "DISCONTINUITY",
+            "VERSION"
+        };
+
+        if (*peek++ != '#')
+            continue;
+
+        if (size < 6)
+            continue;
+
+        if (memcmp(peek, "EXT-X-", 6))
+            continue;
+
+        peek += 6;
+        size -= 6;
+
+        for (size_t i = 0; i < ARRAY_SIZE(ext); i++)
         {
-            for (unsigned int i = 0; i < ARRAY_SIZE(ext); i++)
-            {
-                char *p = strstr((const char*)peek, ext[i]);
-                if (p != NULL)
-                    return true;
-            }
+            size_t len = strlen(ext[i]);
+            if (size < len)
+                continue;
+            if (!memcmp(peek, ext[i], len))
+                return true;
         }
-        peek++;
-    };
+    }
 
     return false;
 }



More information about the vlc-commits mailing list