A webserver omits the Content-Type or if mime-magic fails for unexpected
reasons, probing an image HTTP URL with query parameters will fail in
the extension match.

So check the protocol used is http or https, and drop anything after
the first query parameter when evaluating an image URL.

Signed-off-by: Vittorio Giovara <vittorio.giov...@gmail.com>
---
Here is the correct patch I had in mind.
Cheers,
    Vittorio

 libavformat/format.c | 16 ++++++++++++++--
 1 file changed, 14 insertions(+), 2 deletions(-)

diff --git a/libavformat/format.c b/libavformat/format.c
index 24b7205..77e1155 100644
--- a/libavformat/format.c
+++ b/libavformat/format.c
@@ -76,22 +76,34 @@ void av_register_output_format(AVOutputFormat *format)
 
 int av_match_ext(const char *filename, const char *extensions)
 {
-    const char *ext, *p;
+    const char *ext, *extra, *p;
     char ext1[32], *q;
+    int len, is_http;
 
     if (!filename)
         return 0;
 
+    is_http = av_strstart(filename, "http://";, NULL) ||
+              av_strstart(filename, "https://";, NULL);
+
     ext = strrchr(filename, '.');
     if (ext) {
         ext++;
+
+        len = strlen(ext);
+        if (is_http) {
+            extra = strrchr(ext, '?');
+            if (extra)
+                len -= strlen(extra);
+        }
+
         p = extensions;
         for (;;) {
             q = ext1;
             while (*p != '\0' && *p != ','  && q - ext1 < sizeof(ext1) - 1)
                 *q++ = *p++;
             *q = '\0';
-            if (!av_strcasecmp(ext1, ext))
+            if (!av_strncasecmp(ext1, ext, len))
                 return 1;
             if (*p == '\0')
                 break;
-- 
2.7.0

_______________________________________________
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to