History

libavformat: Remove MAX_PATH limit and use UTF-8 version of getenv()

1. getenv() is replaced with getenv_utf8() across libavformat. 2. New versions of AviSynth+ are now called with UTF-8 filenames. 3. Old versions of AviSynth are still using ANSI strings, but MAX_PATH limit on filename is removed.

Nil Admirari committed 4 years ago

Commit c381f541 parent 13350e84 files · +74 −34Browse files

Unified · Split

4 files
  1. libavformat/avisynth.c +27 −12
  2. libavformat/http.c +14 −8
  3. libavformat/ipfsgateway.c +24 −12
  4. libavformat/tls.c +9 −2
libavformat/avisynth.c+27−12
@@ -34,6 +34,7 @@ · 33 unmodified lines
3434 /* Platform-specific directives. */
3535 #ifdef _WIN32
3636 #include "compat/w32dlfcn.h"
37+ #include "libavutil/wchar_filename.h"
3738 #undef EXTERN_C
3839 #define AVISYNTH_LIB "avisynth"
3940 #else
@@ -56,6 +57,7 @@ typedef struct AviSynthLibrary { · 16 unmodified lines
5657 #define AVSC_DECLARE_FUNC(name) name ## _func name
5758 AVSC_DECLARE_FUNC(avs_bit_blt);
5859 AVSC_DECLARE_FUNC(avs_clip_get_error);
60+ AVSC_DECLARE_FUNC(avs_check_version);
5961 AVSC_DECLARE_FUNC(avs_create_script_environment);
6062 AVSC_DECLARE_FUNC(avs_delete_script_environment);
6163 AVSC_DECLARE_FUNC(avs_get_audio);
@@ -137,6 +139,7 @@ static av_cold int avisynth_load_library(void) · 75 unmodified lines
137139
138140 LOAD_AVS_FUNC(avs_bit_blt, 0);
139141 LOAD_AVS_FUNC(avs_clip_get_error, 0);
142+ LOAD_AVS_FUNC(avs_check_version, 0);
140143 LOAD_AVS_FUNC(avs_create_script_environment, 0);
141144 LOAD_AVS_FUNC(avs_delete_script_environment, 0);
142145 LOAD_AVS_FUNC(avs_get_audio, 0);
@@ -807,26 +810,38 @@ static int avisynth_create_stream(AVFormatContext *s) · 664 unmodified lines
807810 static int avisynth_open_file(AVFormatContext *s)
808811 {
809812 AviSynthContext *avs = s->priv_data;
810− AVS_Value arg, val;
813+ AVS_Value val;
811814 int ret;
812−#ifdef _WIN32
813− char filename_ansi[MAX_PATH * 4];
814− wchar_t filename_wc[MAX_PATH * 4];
815−#endif
816815
817816 if (ret = avisynth_context_create(s))
818817 return ret;
819818
819+ if (!avs_library.avs_check_version(avs->env, 7)) {
820+ AVS_Value args[] = {
821+ avs_new_value_string(s->url),
822+ avs_new_value_bool(1) // filename is in UTF-8
823+ };
824+ val = avs_library.avs_invoke(avs->env, "Import",
825+ avs_new_value_array(args, 2), 0);
826+ } else {
827+ AVS_Value arg;
820828 #ifdef _WIN32
821− /* Convert UTF-8 to ANSI code page */
822− MultiByteToWideChar(CP_UTF8, 0, s->url, -1, filename_wc, MAX_PATH * 4);
823− WideCharToMultiByte(CP_THREAD_ACP, 0, filename_wc, -1, filename_ansi,
824− MAX_PATH * 4, NULL, NULL);
825− arg = avs_new_value_string(filename_ansi);
829+ char *filename_ansi;
830+ /* Convert UTF-8 to ANSI code page */
831+ if (utf8toansi(s->url, &filename_ansi)) {
832+ ret = AVERROR_UNKNOWN;
833+ goto fail;
834+ }
835+ arg = avs_new_value_string(filename_ansi);
826836 #else
827− arg = avs_new_value_string(s->url);
837+ arg = avs_new_value_string(s->url);
828838 #endif
829− val = avs_library.avs_invoke(avs->env, "Import", arg, 0);
839+ val = avs_library.avs_invoke(avs->env, "Import", arg, 0);
840+#ifdef _WIN32
841+ av_free(filename_ansi);
842+#endif
843+ }
844+
830845 if (avs_is_error(val)) {
831846 av_log(s, AV_LOG_ERROR, "%s\n", avs_as_error(val));
832847 ret = AVERROR_UNKNOWN;
libavformat/http.c+14−8
@@ -29,6 +29,7 @@ · 28 unmodified lines
2929 #include "libavutil/avassert.h"
3030 #include "libavutil/avstring.h"
3131 #include "libavutil/bprint.h"
32+#include "libavutil/getenv_utf8.h"
3233 #include "libavutil/opt.h"
3334 #include "libavutil/time.h"
3435 #include "libavutil/parseutils.h"
@@ -198,12 +199,13 @@ void ff_http_init_auth_state(URLContext *dest, const URLContext *src) · 163 unmodified lines
198199 static int http_open_cnx_internal(URLContext *h, AVDictionary **options)
199200 {
200201 const char *path, *proxy_path, *lower_proto = "tcp", *local_path;
202+ char *env_http_proxy, *env_no_proxy;
201203 char *hashmark;
202204 char hostname[1024], hoststr[1024], proto[10];
203205 char auth[1024], proxyauth[1024] = "";
204206 char path1[MAX_URL_SIZE], sanitized_path[MAX_URL_SIZE + 1];
205207 char buf[1024], urlbuf[MAX_URL_SIZE];
206− int port, use_proxy, err;
208+ int port, use_proxy, err = 0;
207209 HTTPContext *s = h->priv_data;
208210
209211 av_url_split(proto, sizeof(proto), auth, sizeof(auth),
@@ -211,9 +213,13 @@ static int http_open_cnx_internal(URLContext *h, AVDictionary **options) · 1 unmodified line
211213 path1, sizeof(path1), s->location);
212214 ff_url_join(hoststr, sizeof(hoststr), NULL, NULL, hostname, port, NULL);
213215
214− proxy_path = s->http_proxy ? s->http_proxy : getenv("http_proxy");
215− use_proxy = !ff_http_match_no_proxy(getenv("no_proxy"), hostname) &&
216+ env_http_proxy = getenv_utf8("http_proxy");
217+ proxy_path = s->http_proxy ? s->http_proxy : env_http_proxy;
218+
219+ env_no_proxy = getenv_utf8("no_proxy");
220+ use_proxy = !ff_http_match_no_proxy(env_no_proxy, hostname) &&
216221 proxy_path && av_strstart(proxy_path, "http://", NULL);
222+ freeenv_utf8(env_no_proxy);
217223
218224 if (!strcmp(proto, "https")) {
219225 lower_proto = "tls";
@@ -224,7 +230,7 @@ static int http_open_cnx_internal(URLContext *h, AVDictionary **options) · 4 unmodified lines
224230 if (s->http_proxy) {
225231 err = av_dict_set(options, "http_proxy", s->http_proxy, 0);
226232 if (err < 0)
227− return err;
233+ goto end;
228234 }
229235 }
230236 if (port < 0)
@@ -259,12 +265,12 @@ static int http_open_cnx_internal(URLContext *h, AVDictionary **options) · 28 unmodified lines
259265 err = ffurl_open_whitelist(&s->hd, buf, AVIO_FLAG_READ_WRITE,
260266 &h->interrupt_callback, options,
261267 h->protocol_whitelist, h->protocol_blacklist, h);
262− if (err < 0)
263− return err;
264268 }
265269
266− return http_connect(h, path, local_path, hoststr,
267− auth, proxyauth);
270+end:
271+ freeenv_utf8(env_http_proxy);
272+ return err < 0 ? err : http_connect(
273+ h, path, local_path, hoststr, auth, proxyauth);
268274 }
269275
270276 static int http_should_reconnect(HTTPContext *s, int err)
libavformat/ipfsgateway.c+24−12
@@ -20,6 +20,7 @@ · 19 unmodified lines
2020 */
2121
2222 #include "libavutil/avstring.h"
23+#include "libavutil/getenv_utf8.h"
2324 #include "libavutil/opt.h"
2425 #include <sys/stat.h>
2526 #include "os_support.h"
@@ -55,12 +56,15 @@ static int populate_ipfs_gateway(URLContext *h) · 29 unmodified lines
5556 int stat_ret = 0;
5657 int ret = AVERROR(EINVAL);
5758 FILE *gateway_file = NULL;
59+ char *env_ipfs_gateway, *env_ipfs_path;
5860
5961 // Test $IPFS_GATEWAY.
60− if (getenv("IPFS_GATEWAY") != NULL) {
61− if (snprintf(c->gateway_buffer, sizeof(c->gateway_buffer), "%s",
62− getenv("IPFS_GATEWAY"))
63− >= sizeof(c->gateway_buffer)) {
62+ env_ipfs_gateway = getenv_utf8("IPFS_GATEWAY");
63+ if (env_ipfs_gateway != NULL) {
64+ int printed = snprintf(c->gateway_buffer, sizeof(c->gateway_buffer),
65+ "%s", env_ipfs_gateway);
66+ freeenv_utf8(env_ipfs_gateway);
67+ if (printed >= sizeof(c->gateway_buffer)) {
6468 av_log(h, AV_LOG_WARNING,
6569 "The IPFS_GATEWAY environment variable "
6670 "exceeds the maximum length. "
@@ -77,20 +81,26 @@ static int populate_ipfs_gateway(URLContext *h) · 10 unmodified lines
7781
7882 // We need to know the IPFS folder to - eventually - read the contents of
7983 // the "gateway" file which would tell us the gateway to use.
80− if (getenv("IPFS_PATH") == NULL) {
84+ env_ipfs_path = getenv_utf8("IPFS_PATH");
85+ if (env_ipfs_path == NULL) {
86+ int printed;
87+ char *env_home = getenv_utf8("HOME");
88+
8189 av_log(h, AV_LOG_DEBUG, "$IPFS_PATH is empty.\n");
8290
8391 // Try via the home folder.
84− if (getenv("HOME") == NULL) {
92+ if (env_home == NULL) {
8593 av_log(h, AV_LOG_WARNING, "$HOME appears to be empty.\n");
8694 ret = AVERROR(EINVAL);
8795 goto err;
8896 }
8997
9098 // Verify the composed path fits.
91− if (snprintf(ipfs_full_data_folder, sizeof(ipfs_full_data_folder),
92− "%s/.ipfs/", getenv("HOME"))
93− >= sizeof(ipfs_full_data_folder)) {
99+ printed = snprintf(
100+ ipfs_full_data_folder, sizeof(ipfs_full_data_folder),
101+ "%s/.ipfs/", env_home);
102+ freeenv_utf8(env_home);
103+ if (printed >= sizeof(ipfs_full_data_folder)) {
94104 av_log(h, AV_LOG_WARNING,
95105 "The IPFS data path exceeds the "
96106 "max path length (%zu)\n",
@@ -113,9 +123,11 @@ static int populate_ipfs_gateway(URLContext *h) · 16 unmodified lines
113123 goto err;
114124 }
115125 } else {
116− if (snprintf(ipfs_full_data_folder, sizeof(ipfs_full_data_folder), "%s",
117− getenv("IPFS_PATH"))
118− >= sizeof(ipfs_full_data_folder)) {
126+ int printed = snprintf(
127+ ipfs_full_data_folder, sizeof(ipfs_full_data_folder),
128+ "%s", env_ipfs_path);
129+ freeenv_utf8(env_ipfs_path);
130+ if (printed >= sizeof(ipfs_full_data_folder)) {
119131 av_log(h, AV_LOG_WARNING,
120132 "The IPFS_PATH environment variable "
121133 "exceeds the maximum length. "
libavformat/tls.c+9−2
@@ -26,6 +26,7 @@ · 25 unmodified lines
2626 #include "url.h"
2727 #include "tls.h"
2828 #include "libavutil/avstring.h"
29+#include "libavutil/getenv_utf8.h"
2930 #include "libavutil/opt.h"
3031 #include "libavutil/parseutils.h"
3132
@@ -60,6 +61,7 @@ int ff_tls_open_underlying(TLSShared *c, URLContext *parent, const char *uri, AV · 28 unmodified lines
6061 char buf[200], opts[50] = "";
6162 struct addrinfo hints = { 0 }, *ai = NULL;
6263 const char *proxy_path;
64+ char *env_http_proxy, *env_no_proxy;
6365 int use_proxy;
6466
6567 set_options(c, uri);
@@ -89,9 +91,13 @@ int ff_tls_open_underlying(TLSShared *c, URLContext *parent, const char *uri, AV · 23 unmodified lines
8991 if (!c->host && !(c->host = av_strdup(c->underlying_host)))
9092 return AVERROR(ENOMEM);
9193
92− proxy_path = c->http_proxy ? c->http_proxy : getenv("http_proxy");
93− use_proxy = !ff_http_match_no_proxy(getenv("no_proxy"), c->underlying_host) &&
94+ env_http_proxy = getenv_utf8("http_proxy");
95+ proxy_path = c->http_proxy ? c->http_proxy : env_http_proxy;
96+
97+ env_no_proxy = getenv_utf8("no_proxy");
98+ use_proxy = !ff_http_match_no_proxy(env_no_proxy, c->underlying_host) &&
9499 proxy_path && av_strstart(proxy_path, "http://", NULL);
100+ freeenv_utf8(env_no_proxy);
95101
96102 if (use_proxy) {
97103 char proxy_host[200], proxy_auth[200], dest[200];
@@ -104,6 +110,7 @@ int ff_tls_open_underlying(TLSShared *c, URLContext *parent, const char *uri, AV · 6 unmodified lines
104110 proxy_port, "/%s", dest);
105111 }
106112
113+ freeenv_utf8(env_http_proxy);
107114 return ffurl_open_whitelist(&c->tcp, buf, AVIO_FLAG_READ_WRITE,
108115 &parent->interrupt_callback, options,
109116 parent->protocol_whitelist, parent->protocol_blacklist, parent);

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t