From patchwork Sun Jun 19 11:40:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nil Admirari X-Patchwork-Id: 36339 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1a22:b0:84:42e0:ad30 with SMTP id cj34csp1100032pzb; Sun, 19 Jun 2022 04:42:00 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sHHyV9hh3mCPGCSkIqkrYf6qlVN20ZHEAcUZPi5rngQ6RqVEpjUG/vOqPIb9Gc/p/nDzqf X-Received: by 2002:aa7:cd66:0:b0:435:74d5:2d58 with SMTP id ca6-20020aa7cd66000000b0043574d52d58mr5710632edb.34.1655638920320; Sun, 19 Jun 2022 04:42:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655638920; cv=none; d=google.com; s=arc-20160816; b=qSGF4esM09b9p1iTivEdwt1XFf+bu7T4ji+CFrebLGFXFv1OJxJ2k/R+ZtR0/ketTQ sDoKnnQrL6F2Fywd+lTInRj6/EyXLEMziCAVctx6jChTuAv+0189/BT6AQFeXFCfhmy1 Ai1qT77H88qnElJfVXAF2/wozmJZSPieuQ6wKONw6YEeznO9S9TSv/LPSxxYOOHUPcnH pQRQJqSFdggWbScmcJ+dbcMvIhEh5DHnPZ9alN//HyRo4Ul4OHxeRXP+nK/M6bdl8dZq HZNW8JP0kVtmtzlJq0xFvDdpZgMQVu/YnM57APj2CaWlGnvS9Rb4dsMrWtS6Pl+mfIWl orgQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=j3jI25pnLTDoEDhAINZO8InXmkfUhL4AnYDEUJKRpQo=; b=XA7RoW5DzTMQJqn2sc38s7VQ+pntetEjpsrkxn0NQfIQDVsvKri9h0wwHz01lOMD8z zSyxwbSz7aMgLpRMMlPNmrd4RKIumBh24Ez+PmADFawsyD5xtSmK6an4mIC8dytLHz3o nEweo/ZsIhyXPdeC+3wKFfzGSGMI6RihMTif2hB64aQnDG5CO6Ri4Gwb9xWU6KD2PDx1 h8z8r5xPmD8udg30e1ObToc9b2G374/e9fn2BMWzwsBDXQkNSPRPe3Bri6dEehD81HpT cs91y81vEz6owLHQIq3yDpMjEVgq9554CIxUzlfAOtLs5nDao7Lnc02ZPtcRHUihNWle 5r8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@mailo.com header.s=mailo header.b=cxFhv+mC; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mailo.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id g18-20020a170906521200b00718d0604af4si6629072ejm.604.2022.06.19.04.41.59; Sun, 19 Jun 2022 04:42:00 -0700 (PDT) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@mailo.com header.s=mailo header.b=cxFhv+mC; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=mailo.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id C824A68B5DB; Sun, 19 Jun 2022 14:41:20 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from msg-6.mailo.com (ip-16.mailobj.net [213.182.54.16]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id EF84468B38D for ; Sun, 19 Jun 2022 14:41:09 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailo.com; s=mailo; t=1655638868; bh=mLdNeQBI/MEwVrO3UJXXGZbLpwvbK/mugR1AVbkM8ZI=; h=X-EA-Auth:From:To:Subject:Date:Message-Id:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding; b=cxFhv+mC38UZ7ZMapgVcXHmiHrTooP6C9v9n3dTwKSaWxB/gITcFg/ODliKm3VDzA 7ja1RdU7Ev7ZAS/zx7IjvABCC1Dop5ybt/sR6XNq0kacalhIdJvRrsWxScNxxTmVpv XntqCJTTjGbkTUPtwd1p32a8363y6TDPfL1r4PK0= Received: by b-1.in.mailobj.net [192.168.90.11] with ESMTP via ip-206.mailobj.net [213.182.55.206] Sun, 19 Jun 2022 13:41:08 +0200 (CEST) X-EA-Auth: WYQE+ZfoUucfIU2e8NO2hJHe0ZhIAq6B2GEyGkrXt9v/1ycpCJxdSbaACgYl+E2lDcp13SpADDkraiugTJ/gx5EgBoZNtxsjOqv29YJFEMk= From: Nil Admirari To: ffmpeg-devel@ffmpeg.org Date: Sun, 19 Jun 2022 14:40:55 +0300 Message-Id: <20220619114056.5582-4-nil-admirari@mailo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220619114056.5582-1-nil-admirari@mailo.com> References: <20220619114056.5582-1-nil-admirari@mailo.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v19 4/5] libavformat: Remove MAX_PATH limit and use UTF-8 version of getenv() X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: O32G54UnFDz2 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. --- libavformat/avisynth.c | 39 +++++++++++++++++++++++++++------------ libavformat/http.c | 22 ++++++++++++++-------- libavformat/ipfsgateway.c | 35 +++++++++++++++++++++++------------ libavformat/tls.c | 11 +++++++++-- 4 files changed, 73 insertions(+), 34 deletions(-) diff --git a/libavformat/avisynth.c b/libavformat/avisynth.c index 8ba2bdead2..a97d12b6b6 100644 --- a/libavformat/avisynth.c +++ b/libavformat/avisynth.c @@ -34,6 +34,7 @@ /* Platform-specific directives. */ #ifdef _WIN32 #include "compat/w32dlfcn.h" + #include "libavutil/wchar_filename.h" #undef EXTERN_C #define AVISYNTH_LIB "avisynth" #else @@ -56,6 +57,7 @@ typedef struct AviSynthLibrary { #define AVSC_DECLARE_FUNC(name) name ## _func name AVSC_DECLARE_FUNC(avs_bit_blt); AVSC_DECLARE_FUNC(avs_clip_get_error); + AVSC_DECLARE_FUNC(avs_check_version); AVSC_DECLARE_FUNC(avs_create_script_environment); AVSC_DECLARE_FUNC(avs_delete_script_environment); AVSC_DECLARE_FUNC(avs_get_audio); @@ -137,6 +139,7 @@ static av_cold int avisynth_load_library(void) LOAD_AVS_FUNC(avs_bit_blt, 0); LOAD_AVS_FUNC(avs_clip_get_error, 0); + LOAD_AVS_FUNC(avs_check_version, 0); LOAD_AVS_FUNC(avs_create_script_environment, 0); LOAD_AVS_FUNC(avs_delete_script_environment, 0); LOAD_AVS_FUNC(avs_get_audio, 0); @@ -807,26 +810,38 @@ static int avisynth_create_stream(AVFormatContext *s) static int avisynth_open_file(AVFormatContext *s) { AviSynthContext *avs = s->priv_data; - AVS_Value arg, val; + AVS_Value val; int ret; -#ifdef _WIN32 - char filename_ansi[MAX_PATH * 4]; - wchar_t filename_wc[MAX_PATH * 4]; -#endif if (ret = avisynth_context_create(s)) return ret; + if (!avs_library.avs_check_version(avs->env, 7)) { + AVS_Value args[] = { + avs_new_value_string(s->url), + avs_new_value_bool(1) // filename is in UTF-8 + }; + val = avs_library.avs_invoke(avs->env, "Import", + avs_new_value_array(args, 2), 0); + } else { + AVS_Value arg; #ifdef _WIN32 - /* Convert UTF-8 to ANSI code page */ - MultiByteToWideChar(CP_UTF8, 0, s->url, -1, filename_wc, MAX_PATH * 4); - WideCharToMultiByte(CP_THREAD_ACP, 0, filename_wc, -1, filename_ansi, - MAX_PATH * 4, NULL, NULL); - arg = avs_new_value_string(filename_ansi); + char *filename_ansi; + /* Convert UTF-8 to ANSI code page */ + if (utf8toansi(s->url, &filename_ansi)) { + ret = AVERROR_UNKNOWN; + goto fail; + } + arg = avs_new_value_string(filename_ansi); #else - arg = avs_new_value_string(s->url); + arg = avs_new_value_string(s->url); #endif - val = avs_library.avs_invoke(avs->env, "Import", arg, 0); + val = avs_library.avs_invoke(avs->env, "Import", arg, 0); +#ifdef _WIN32 + av_free(filename_ansi); +#endif + } + if (avs_is_error(val)) { av_log(s, AV_LOG_ERROR, "%s\n", avs_as_error(val)); ret = AVERROR_UNKNOWN; diff --git a/libavformat/http.c b/libavformat/http.c index c8f3f4b6a3..f80ea7bf35 100644 --- a/libavformat/http.c +++ b/libavformat/http.c @@ -29,6 +29,7 @@ #include "libavutil/avassert.h" #include "libavutil/avstring.h" #include "libavutil/bprint.h" +#include "libavutil/getenv_utf8.h" #include "libavutil/opt.h" #include "libavutil/time.h" #include "libavutil/parseutils.h" @@ -198,12 +199,13 @@ void ff_http_init_auth_state(URLContext *dest, const URLContext *src) static int http_open_cnx_internal(URLContext *h, AVDictionary **options) { const char *path, *proxy_path, *lower_proto = "tcp", *local_path; + char *env_http_proxy, *env_no_proxy; char *hashmark; char hostname[1024], hoststr[1024], proto[10]; char auth[1024], proxyauth[1024] = ""; char path1[MAX_URL_SIZE], sanitized_path[MAX_URL_SIZE + 1]; char buf[1024], urlbuf[MAX_URL_SIZE]; - int port, use_proxy, err; + int port, use_proxy, err = 0; HTTPContext *s = h->priv_data; av_url_split(proto, sizeof(proto), auth, sizeof(auth), @@ -211,9 +213,13 @@ static int http_open_cnx_internal(URLContext *h, AVDictionary **options) path1, sizeof(path1), s->location); ff_url_join(hoststr, sizeof(hoststr), NULL, NULL, hostname, port, NULL); - proxy_path = s->http_proxy ? s->http_proxy : getenv("http_proxy"); - use_proxy = !ff_http_match_no_proxy(getenv("no_proxy"), hostname) && + env_http_proxy = getenv_utf8("http_proxy"); + proxy_path = s->http_proxy ? s->http_proxy : env_http_proxy; + + env_no_proxy = getenv_utf8("no_proxy"); + use_proxy = !ff_http_match_no_proxy(env_no_proxy, hostname) && proxy_path && av_strstart(proxy_path, "http://", NULL); + freeenv_utf8(env_no_proxy); if (!strcmp(proto, "https")) { lower_proto = "tls"; @@ -224,7 +230,7 @@ static int http_open_cnx_internal(URLContext *h, AVDictionary **options) if (s->http_proxy) { err = av_dict_set(options, "http_proxy", s->http_proxy, 0); if (err < 0) - return err; + goto end; } } if (port < 0) @@ -259,12 +265,12 @@ static int http_open_cnx_internal(URLContext *h, AVDictionary **options) err = ffurl_open_whitelist(&s->hd, buf, AVIO_FLAG_READ_WRITE, &h->interrupt_callback, options, h->protocol_whitelist, h->protocol_blacklist, h); - if (err < 0) - return err; } - return http_connect(h, path, local_path, hoststr, - auth, proxyauth); +end: + freeenv_utf8(env_http_proxy); + return err < 0 ? err : http_connect( + h, path, local_path, hoststr, auth, proxyauth); } static int http_should_reconnect(HTTPContext *s, int err) diff --git a/libavformat/ipfsgateway.c b/libavformat/ipfsgateway.c index 83d52293b4..3793ccfa6d 100644 --- a/libavformat/ipfsgateway.c +++ b/libavformat/ipfsgateway.c @@ -20,6 +20,7 @@ */ #include "libavutil/avstring.h" +#include "libavutil/getenv_utf8.h" #include "libavutil/opt.h" #include #include "os_support.h" @@ -55,12 +56,15 @@ static int populate_ipfs_gateway(URLContext *h) int stat_ret = 0; int ret = AVERROR(EINVAL); FILE *gateway_file = NULL; + char *env_ipfs_gateway, *env_ipfs_path; // Test $IPFS_GATEWAY. - if (getenv("IPFS_GATEWAY") != NULL) { - if (snprintf(c->gateway_buffer, sizeof(c->gateway_buffer), "%s", - getenv("IPFS_GATEWAY")) - >= sizeof(c->gateway_buffer)) { + env_ipfs_gateway = getenv_utf8("IPFS_GATEWAY"); + if (env_ipfs_gateway != NULL) { + int printed = snprintf(c->gateway_buffer, sizeof(c->gateway_buffer), + "%s", env_ipfs_gateway); + freeenv_utf8(env_ipfs_gateway); + if (printed >= sizeof(c->gateway_buffer)) { av_log(h, AV_LOG_WARNING, "The IPFS_GATEWAY environment variable " "exceeds the maximum length. " @@ -77,20 +81,25 @@ static int populate_ipfs_gateway(URLContext *h) // We need to know the IPFS folder to - eventually - read the contents of // the "gateway" file which would tell us the gateway to use. - if (getenv("IPFS_PATH") == NULL) { + env_ipfs_path = getenv_utf8("IPFS_PATH"); + if (env_ipfs_path == NULL) { + char *env_home = getenv_utf8("HOME"); + av_log(h, AV_LOG_DEBUG, "$IPFS_PATH is empty.\n"); // Try via the home folder. - if (getenv("HOME") == NULL) { + if (env_home == NULL) { av_log(h, AV_LOG_WARNING, "$HOME appears to be empty.\n"); ret = AVERROR(EINVAL); goto err; } // Verify the composed path fits. - if (snprintf(ipfs_full_data_folder, sizeof(ipfs_full_data_folder), - "%s/.ipfs/", getenv("HOME")) - >= sizeof(ipfs_full_data_folder)) { + int printed = snprintf( + ipfs_full_data_folder, sizeof(ipfs_full_data_folder), + "%s/.ipfs/", env_home); + freeenv_utf8(env_home); + if (printed >= sizeof(ipfs_full_data_folder)) { av_log(h, AV_LOG_WARNING, "The IPFS data path exceeds the " "max path length (%zu)\n", @@ -113,9 +122,11 @@ static int populate_ipfs_gateway(URLContext *h) goto err; } } else { - if (snprintf(ipfs_full_data_folder, sizeof(ipfs_full_data_folder), "%s", - getenv("IPFS_PATH")) - >= sizeof(ipfs_full_data_folder)) { + int printed = snprintf( + ipfs_full_data_folder, sizeof(ipfs_full_data_folder), + "%s", env_ipfs_path); + freeenv_utf8(env_ipfs_path); + if (printed >= sizeof(ipfs_full_data_folder)) { av_log(h, AV_LOG_WARNING, "The IPFS_PATH environment variable " "exceeds the maximum length. " diff --git a/libavformat/tls.c b/libavformat/tls.c index 302c0f8d59..e42d399862 100644 --- a/libavformat/tls.c +++ b/libavformat/tls.c @@ -26,6 +26,7 @@ #include "url.h" #include "tls.h" #include "libavutil/avstring.h" +#include "libavutil/getenv_utf8.h" #include "libavutil/opt.h" #include "libavutil/parseutils.h" @@ -60,6 +61,7 @@ int ff_tls_open_underlying(TLSShared *c, URLContext *parent, const char *uri, AV char buf[200], opts[50] = ""; struct addrinfo hints = { 0 }, *ai = NULL; const char *proxy_path; + char *env_http_proxy, *env_no_proxy; int use_proxy; set_options(c, uri); @@ -89,9 +91,13 @@ int ff_tls_open_underlying(TLSShared *c, URLContext *parent, const char *uri, AV if (!c->host && !(c->host = av_strdup(c->underlying_host))) return AVERROR(ENOMEM); - proxy_path = c->http_proxy ? c->http_proxy : getenv("http_proxy"); - use_proxy = !ff_http_match_no_proxy(getenv("no_proxy"), c->underlying_host) && + env_http_proxy = getenv_utf8("http_proxy"); + proxy_path = c->http_proxy ? c->http_proxy : env_http_proxy; + + env_no_proxy = getenv_utf8("no_proxy"); + use_proxy = !ff_http_match_no_proxy(env_no_proxy, c->underlying_host) && proxy_path && av_strstart(proxy_path, "http://", NULL); + freeenv_utf8(env_no_proxy); if (use_proxy) { 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 proxy_port, "/%s", dest); } + freeenv_utf8(env_http_proxy); return ffurl_open_whitelist(&c->tcp, buf, AVIO_FLAG_READ_WRITE, &parent->interrupt_callback, options, parent->protocol_whitelist, parent->protocol_blacklist, parent);