[FFmpeg-devel] [PATCH] libavformat/url: check url root node when rel include double dot

Steven Liu lq at chinaffmpeg.org
Mon Apr 27 13:24:05 EEST 2020


fix ticket: 8625

Signed-off-by: Steven Liu <lq at chinaffmpeg.org>
---
 libavformat/url.c | 22 ++++++++++++++++++++--
 1 file changed, 20 insertions(+), 2 deletions(-)

diff --git a/libavformat/url.c b/libavformat/url.c
index 596fb49cfc..e5003f795a 100644
--- a/libavformat/url.c
+++ b/libavformat/url.c
@@ -81,6 +81,8 @@ void ff_make_absolute_url(char *buf, int size, const char *base,
                           const char *rel)
 {
     char *sep, *path_query;
+    char *root = NULL;
+    char *p = NULL;
     /* Absolute path, relative to the current server */
     if (base && strstr(base, "://") && rel[0] == '/') {
         if (base != buf)
@@ -120,16 +122,32 @@ void ff_make_absolute_url(char *buf, int size, const char *base,
         return;
     }
 
+    p = buf;
+    /* Get the path root of the url which start by "://" */
+    if (p && strstr(p, "://")) {
+        sep = strstr(p, "://");
+        if (sep) {
+            sep += 3;
+            root = strchr(sep, '/');
+        }
+    }
+
     /* Remove the file name from the base url */
     sep = strrchr(buf, '/');
+    if (sep <= root)
+        sep = root;
+
     if (sep)
         sep[1] = '\0';
     else
         buf[0] = '\0';
     while (av_strstart(rel, "../", NULL) && sep) {
         /* Remove the path delimiter at the end */
-        sep[0] = '\0';
-        sep = strrchr(buf, '/');
+        if (sep > root) {
+            sep[0] = '\0';
+            sep = strrchr(buf, '/');
+        }
+
         /* If the next directory name to pop off is "..", break here */
         if (!strcmp(sep ? &sep[1] : buf, "..")) {
             /* Readd the slash we just removed */
-- 
2.25.0





More information about the ffmpeg-devel mailing list