fix ticket: 8625 and add testcase into url for double dot corner case Suggested-by: Martin Storsjö <mar...@martin.st> Signed-off-by: Steven Liu <liuq...@kuaishou.com> --- libavformat/tests/url.c | 3 +++ libavformat/url.c | 21 +++++++++++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-)
diff --git a/libavformat/tests/url.c b/libavformat/tests/url.c index 5e484fd428..02d0d59aa8 100644 --- a/libavformat/tests/url.c +++ b/libavformat/tests/url.c @@ -56,6 +56,7 @@ int main(void) test("/foo/bar", "baz"); test("/foo/bar", "../baz"); test("/foo/bar", "/baz"); + test("/foo/bar", "../../../baz"); test("http://server/foo/", "baz"); test("http://server/foo/bar", "baz"); test("http://server/foo/", "../baz"); @@ -65,6 +66,8 @@ int main(void) test("http://server/foo/bar?param=value/with/slashes", "/baz"); test("http://server/foo/bar?param&otherparam", "?someparam"); test("http://server/foo/bar", "//other/url"); + test("http://server/foo/bar", "../../../../../other/url"); + test("http://server/foo/bar", "/../../../../../other/url"); printf("\nTesting av_url_split:\n"); test2("/foo/bar"); diff --git a/libavformat/url.c b/libavformat/url.c index 596fb49cfc..0aa50ab9a7 100644 --- a/libavformat/url.c +++ b/libavformat/url.c @@ -81,6 +81,7 @@ void ff_make_absolute_url(char *buf, int size, const char *base, const char *rel) { char *sep, *path_query; + char *root, *p; /* Absolute path, relative to the current server */ if (base && strstr(base, "://") && rel[0] == '/') { if (base != buf) @@ -120,16 +121,32 @@ void ff_make_absolute_url(char *buf, int size, const char *base, return; } + root = 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 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".