From patchwork Sun Jun 19 11:40:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nil Admirari X-Patchwork-Id: 36337 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1a22:b0:84:42e0:ad30 with SMTP id cj34csp1099916pzb; Sun, 19 Jun 2022 04:41:39 -0700 (PDT) X-Google-Smtp-Source: AGRyM1spLK+04hgK0RV9c4KNHmiHfYEF5+L0p8uMyMOnriPJlPqqfR0iyTCYD9CHVCh+c7kuUD2F X-Received: by 2002:a05:6402:3293:b0:42e:18a:d6eb with SMTP id f19-20020a056402329300b0042e018ad6ebmr23249138eda.293.1655638899446; Sun, 19 Jun 2022 04:41:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655638899; cv=none; d=google.com; s=arc-20160816; b=Psw4U3xJC7BoU5B0GBXCJQcJOZh4rxaSrcLiX1Tmf2TbgqIgb9h1IkDYtZg0OOi//2 JJUctRtfDg14ILa95ne8Y7rPucWFmGmVQrJGXtvcxm0IQAd6pcFGWoE15BKh5vmbm925 DepJfkPGY2eMO2KUFSf7NdSYkVl3+LocdA5kYja+uuFCoGMAwxg5ziY9llWQyiXs6Aos kR6O3p2WY1T1fEwtZ/5sDmxMcf+IP74rDajfl3xBZRzaWkTbgJshxnFGdELexrJtn0WR fPlgRENEjNqHWbMDJ4GoSvhYrMc8NiOG6vC3W5jZ7PtCFGNbkQQuLOufd+jNWoaT4ZB4 tJsA== 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:message-id:date:to:from :dkim-signature:delivered-to; bh=Zmzs777rDOZNguG5kzjsRCbAKg+9BaNvG52njSmysp4=; b=XPPKauvtGf2iHoelTVgt98oe6+02l3He62FF5619ic/FJajheGth6QMzzGMW0tdmi6 REqPZ9kru3mIpVa1HdPPHF/gcY8kIHjsBAFc5BrnrUglRtbSRYnpcs3PJMQvmwdY73vi YzXa8LxTDoazhtiAb2eQ48d7lHAXyMYvXmbMOWQvX7Z2g/TNVedIaYiHSJnWYebicDMV /21xB1ECQIbUfQFesWEt5SRDSOq7BiGOLj2D43v9QIqqt1csCgA0N0c07WPRl2CeMoIe 6eFfj35xW+l6iBtKkX8PmkzOaomVDD31hkxtpnUyp0Kl8vgtvOFpqL/T/NQUr+dgQTjE AkcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@mailo.com header.s=mailo header.b=XTQSFHkx; 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 s14-20020a170906778e00b006fec955c743si10019425ejm.375.2022.06.19.04.41.39; Sun, 19 Jun 2022 04:41:39 -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=XTQSFHkx; 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 17A7568B5A2; Sun, 19 Jun 2022 14:41:19 +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 EAA3268B358 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=1655638866; bh=RRdUE8QLFsDh5VNq2fe6sM08bil/sJAcywrvgkdHPAc=; h=X-EA-Auth:From:To:Subject:Date:Message-Id:X-Mailer:MIME-Version: Content-Transfer-Encoding; b=XTQSFHkxY714ENL96BmRFRr+RmELRF7d1LLdkNtSCO9ePoG0GF9kCVELmm7HdNMkE 1snMMYdTk2/6FOuVsS3OEbI6/m2NlwKZo4rcge2pugq7moXvISrOJo1JPT/5pP3coo cCHCNy5L6ZYkmbCL26pEewAofL0tKH+NUUssJ/Sw= 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:06 +0200 (CEST) X-EA-Auth: iw7k0WgavDRmAeDTaRzTiaaXVwvulj1HtGwxFpAgUAgCKSiN31EksmtBH9ZrHY6TNDooyTcQ/3DDid0S7BHg7o3Xuukhmbkhck5yRVM88wc= From: Nil Admirari To: ffmpeg-devel@ffmpeg.org Date: Sun, 19 Jun 2022 14:40:52 +0300 Message-Id: <20220619114056.5582-1-nil-admirari@mailo.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v19 1/5] libavutil: Add wchartoutf8(), wchartoansi(), utf8toansi(), getenv_utf8() and freeenv_utf8() 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: THyN1FfjMtT+ wchartoutf8() converts strings returned by WinAPI into UTF-8, which is FFmpeg's preffered encoding. Some external dependencies, such as AviSynth, are still not Unicode-enabled. utf8toansi() converts UTF-8 strings into ANSI in two steps: UTF-8 -> wchar_t -> ANSI. wchartoansi() is responsible for the second step of the conversion. Conversion in just one step is not supported by WinAPI. Since these character converting functions allocate the buffer of necessary size, they also facilitate the removal of MAX_PATH limit in places where fixed-size ANSI/WCHAR strings were used as filename buffers. getenv_utf8() wraps _wgetenv() converting its input from and its output to UTF-8. Compared to plain getenv(), getenv_utf8() requires a cleanup. Because of that, in places that only test the existence of an environment variable or compare its value with a string consisting entirely of ASCII characters, the use of plain getenv() is still preferred. (libavutil/log.c check_color_terminal() is an example of such a place.) Plain getenv() is also preffered in UNIX-only code, such as bktr.c, fbdev_common.c, oss.c in libavdevice or af_ladspa.c in libavfilter. --- configure | 1 + libavutil/getenv_utf8.h | 83 ++++++++++++++++++++++++++++++++++++++ libavutil/wchar_filename.h | 53 ++++++++++++++++++++++++ 3 files changed, 137 insertions(+) create mode 100644 libavutil/getenv_utf8.h diff --git a/configure b/configure index 7ffbb85e21..3a97610209 100755 --- a/configure +++ b/configure @@ -2272,6 +2272,7 @@ SYSTEM_FUNCS=" fcntl getaddrinfo getauxval + getenv gethrtime getopt GetModuleHandle diff --git a/libavutil/getenv_utf8.h b/libavutil/getenv_utf8.h new file mode 100644 index 0000000000..799fef9839 --- /dev/null +++ b/libavutil/getenv_utf8.h @@ -0,0 +1,83 @@ +/* + * This file is part of FFmpeg. + * + * FFmpeg is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * FFmpeg is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with FFmpeg; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#ifndef AVUTIL_GETENV_UTF8_H +#define AVUTIL_GETENV_UTF8_H + +#include + +#include "config.h" +#include "mem.h" + +#if HAVE_GETENV + +#ifdef _WIN32 + +#include "libavutil/wchar_filename.h" + +static inline char *getenv_utf8(const char *varname) +{ + wchar_t *varname_w, *var_w; + char *var; + + if (utf8towchar(varname, &varname_w)) + return NULL; + if (!varname_w) + return NULL; + + var_w = _wgetenv(varname_w); + av_free(varname_w); + + if (!var_w) + return NULL; + if (wchartoutf8(var_w, &var)) + return NULL; + + return var; + + // No CP_ACP fallback compared to other *_utf8() functions: + // non UTF-8 strings must not be returned. +} + +static inline void freeenv_utf8(const char *var) +{ + av_free(var); +} + +#else + +static inline char *getenv_utf8(const char *varname) +{ + return getenv(varname); +} + +static inline void freeenv_utf8(const char *) +{ +} + +#endif // _WIN32 + +#else + +#define getenv_utf8(x) NULL + +#define freeenv_utf8(x) ((void) 0) + +#endif // HAVE_GETENV + +#endif // AVUTIL_GETENV_UTF8_H diff --git a/libavutil/wchar_filename.h b/libavutil/wchar_filename.h index f36d9dfea3..08de073ed7 100644 --- a/libavutil/wchar_filename.h +++ b/libavutil/wchar_filename.h @@ -20,6 +20,8 @@ #define AVUTIL_WCHAR_FILENAME_H #ifdef _WIN32 + +#define WIN32_LEAN_AND_MEAN #include #include "mem.h" @@ -41,6 +43,57 @@ static inline int utf8towchar(const char *filename_utf8, wchar_t **filename_w) return 0; } +av_warn_unused_result +static inline int wchartocp(unsigned int code_page, const wchar_t *filename_w, + char **filename) +{ + DWORD flags = code_page == CP_UTF8 ? WC_ERR_INVALID_CHARS : 0; + int num_chars = WideCharToMultiByte(code_page, flags, filename_w, -1, + NULL, 0, NULL, NULL); + if (num_chars <= 0) { + *filename = NULL; + return 0; + } + *filename = av_malloc_array(num_chars, sizeof *filename); + if (!*filename) { + errno = ENOMEM; + return -1; + } + WideCharToMultiByte(code_page, flags, filename_w, -1, + *filename, num_chars, NULL, NULL); + return 0; +} + +av_warn_unused_result +static inline int wchartoutf8(const wchar_t *filename_w, char **filename) +{ + return wchartocp(CP_UTF8, filename_w, filename); +} + +av_warn_unused_result +static inline int wchartoansi(const wchar_t *filename_w, char **filename) +{ + return wchartocp(CP_ACP, filename_w, filename); +} + +av_warn_unused_result +static inline int utf8toansi(const char *filename_utf8, char **filename) +{ + wchar_t *filename_w = NULL; + int ret = -1; + if (utf8towchar(filename_utf8, &filename_w)) + return -1; + + if (!filename_w) { + *filename = NULL; + return 0; + } + + ret = wchartoansi(filename_w, filename); + av_free(filename_w); + return ret; +} + /** * Checks for extended path prefixes for which normalization needs to be skipped. * see .NET6: PathInternal.IsExtended() From patchwork Sun Jun 19 11:40:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nil Admirari X-Patchwork-Id: 36336 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1a22:b0:84:42e0:ad30 with SMTP id cj34csp1099865pzb; Sun, 19 Jun 2022 04:41:29 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s1+76olxUjl0Yf9dfTWNNCOKbBnY4ywtvZOqJWzfJQ/9wEt/8kNjeotnMjMXXfFVit9PSO X-Received: by 2002:a17:907:1c8a:b0:6e9:2a0d:d7b7 with SMTP id nb10-20020a1709071c8a00b006e92a0dd7b7mr16297005ejc.572.1655638889703; Sun, 19 Jun 2022 04:41:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655638889; cv=none; d=google.com; s=arc-20160816; b=ve1DEsuz9/Ev4okoXRDOu9gZZj4VVgEsDj+QMXHCaEW6hVXbITVZ7N6lcieK8Hrfzy G2Z/1xMjlpwPB/ZitMx0yfl+8lXnNMl9bEldGFgBjV4Mcu/Jez/VeFyfjQOhkk4svt2g KvTJKrqaDN5dKLVl6gXwmhf08iwUBfje5gLrKu3FKn8FWSHF6fKZd4FkCSp/Xs0ZzKj6 qQ8lvMkF273qfu/b9nu039M7ez+5g+E7x01tPA2KntNx0tghEN+VDQn62JAxb2KqLviw 3pZi0fo51pbzcd+gNXAwi2E9M+cgLMKhiNOsK84eNJEcPTVBOgK4kDXPdBTsmZTY/iiP yVeQ== 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=IaVfbkAMPJmo5ccLZrHX7LP9Zp7x7cao/96Qr/z2YfE=; b=1E3I9se/NZPH+X7IIaqyVxEYbWEmWc/fdWeXu7Pg0fnWQVlUPqjEAJojzbY9iKrHui moKehxDq+kkJc69l1UC4DK2G3Ui1eA0W78Oq498HFlII51AyFh31Hh+4vH0fwXF8pJa2 LlXDn9rYeHnGoD8NbbxhraixJti+9HXEJm7ONlH2YOZns3W8ia36RRGOl1vzy/VcaXTR 5hcm0vjdUyRwZmXZ3qSZG/8mlKGbctaDj5FqbyCJgSk6W9ZbOGj+1OPhqKweRyoTCIbp Er/eiZAX5OQTITBOIWhO5cnwA3nHf5yf0Ha5orC5tPJvBvd2laa7UpTJcwYsCiZmEdZy ASYA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@mailo.com header.s=mailo header.b=Vrkjcodw; 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 b15-20020a056402278f00b0043176d24d56si10128725ede.342.2022.06.19.04.41.29; Sun, 19 Jun 2022 04:41:29 -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=Vrkjcodw; 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 28FF168B03D; Sun, 19 Jun 2022 14:41:18 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from msg-4.mailo.com (ip-15.mailobj.net [213.182.54.15]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E307F68B03D 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=1655638867; bh=c1YRUp7vg5tAKdb+y9E5UgC1j56iaSUBEf360VCix7o=; h=X-EA-Auth:From:To:Subject:Date:Message-Id:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding; b=VrkjcodwjiAawt+k3QHqxPeWi25YiNpUut6tdj5tH8/2Ud5ldmcV8Qk3JHitKZMqE C/mQOUSItV1BvMd744tfKIvyd3TiqIlV21BLe4maW2jF8LFe9qheb7bg8HM0+YyGUQ U0tmEZObcVhDMCZ7BdDck4blMWisRArJEOkNSJmM= 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:07 +0200 (CEST) X-EA-Auth: RK+RgxjZB21+u6zXCWFZEMCeVXUZ8JeplS25gPai6F+GGpmStCQi750+pFHSsGw6UQPk3RBXUwAiL6P1NH2zpJdwQAkSlx0LVUni/bi0BO0= From: Nil Admirari To: ffmpeg-devel@ffmpeg.org Date: Sun, 19 Jun 2022 14:40:53 +0300 Message-Id: <20220619114056.5582-2-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 2/5] compat/w32dlfcn.h: Remove MAX_PATH limit and replace LoadLibraryExA with LoadLibraryExW 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: ydVTCbLF1+oG --- compat/w32dlfcn.h | 100 ++++++++++++++++++++++++++++++++---------- libavcodec/mf_utils.h | 1 + 2 files changed, 79 insertions(+), 22 deletions(-) diff --git a/compat/w32dlfcn.h b/compat/w32dlfcn.h index 52a94efafb..fb1aa1b72e 100644 --- a/compat/w32dlfcn.h +++ b/compat/w32dlfcn.h @@ -20,11 +20,40 @@ #define COMPAT_W32DLFCN_H #ifdef _WIN32 +#include + #include + #include "config.h" -#if (_WIN32_WINNT < 0x0602) || HAVE_WINRT +#include "libavutil/macros.h" #include "libavutil/wchar_filename.h" -#endif + +static inline wchar_t *get_module_filename(HMODULE module) +{ + wchar_t *path = NULL, *new_path; + DWORD path_size = 0, path_len; + + do { + path_size = path_size ? FFMIN(2 * path_size, INT16_MAX + 1) : MAX_PATH; + new_path = av_realloc_array(path, path_size, sizeof *path); + if (!new_path) { + av_free(path); + return NULL; + } + path = new_path; + // Returns path_size in case of insufficient buffer. + // Whether the error is set or not and whether the output + // is null-terminated or not depends on the version of Windows. + path_len = GetModuleFileNameW(module, path, path_size); + } while (path_len && path_size <= INT16_MAX && path_size <= path_len); + + if (!path_len) { + av_free(path); + return NULL; + } + return path; +} + /** * Safe function used to open dynamic libs. This attempts to improve program security * by removing the current directory from the dll search path. Only dll's found in the @@ -34,29 +63,53 @@ */ static inline HMODULE win32_dlopen(const char *name) { + wchar_t *name_w; + HMODULE module = NULL; + if (utf8towchar(name, &name_w)) + name_w = NULL; #if _WIN32_WINNT < 0x0602 - // Need to check if KB2533623 is available + // On Win7 and earlier we check if KB2533623 is available if (!GetProcAddress(GetModuleHandleW(L"kernel32.dll"), "SetDefaultDllDirectories")) { - HMODULE module = NULL; - wchar_t *path = NULL, *name_w = NULL; - DWORD pathlen; - if (utf8towchar(name, &name_w)) + wchar_t *path = NULL, *new_path; + DWORD pathlen, pathsize, namelen; + if (!name_w) goto exit; - path = (wchar_t *)av_calloc(MAX_PATH, sizeof(wchar_t)); + namelen = wcslen(name_w); // Try local directory first - pathlen = GetModuleFileNameW(NULL, path, MAX_PATH); - pathlen = wcsrchr(path, '\\') - path; - if (pathlen == 0 || pathlen + wcslen(name_w) + 2 > MAX_PATH) + path = get_module_filename(NULL); + if (!path) + goto exit; + new_path = wcsrchr(path, '\\'); + if (!new_path) goto exit; - path[pathlen] = '\\'; + pathlen = new_path - path; + pathsize = pathlen + namelen + 2; + new_path = av_realloc_array(path, pathsize, sizeof *path); + if (!new_path) + goto exit; + path = new_path; wcscpy(path + pathlen + 1, name_w); module = LoadLibraryExW(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); if (module == NULL) { // Next try System32 directory - pathlen = GetSystemDirectoryW(path, MAX_PATH); - if (pathlen == 0 || pathlen + wcslen(name_w) + 2 > MAX_PATH) + pathlen = GetSystemDirectoryW(path, pathsize); + if (!pathlen) goto exit; - path[pathlen] = '\\'; + // Buffer is not enough in two cases: + // 1. system directory + \ + module name + // 2. system directory even without the module name. + if (pathlen + namelen + 2 > pathsize) { + pathsize = pathlen + namelen + 2; + new_path = av_realloc_array(path, pathsize, sizeof *path); + if (!new_path) + goto exit; + path = new_path; + // Query again to handle the case #2. + pathlen = GetSystemDirectoryW(path, pathsize); + if (!pathlen) + goto exit; + } + path[pathlen] = L'\\'; wcscpy(path + pathlen + 1, name_w); module = LoadLibraryExW(path, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); } @@ -73,16 +126,19 @@ exit: # define LOAD_LIBRARY_SEARCH_SYSTEM32 0x00000800 #endif #if HAVE_WINRT - wchar_t *name_w = NULL; - int ret; - if (utf8towchar(name, &name_w)) + if (!name_w) return NULL; - ret = LoadPackagedLibrary(name_w, 0); - av_free(name_w); - return ret; + module = LoadPackagedLibrary(name_w, 0); #else - return LoadLibraryExA(name, NULL, LOAD_LIBRARY_SEARCH_APPLICATION_DIR | LOAD_LIBRARY_SEARCH_SYSTEM32); +#define LOAD_FLAGS (LOAD_LIBRARY_SEARCH_APPLICATION_DIR | LOAD_LIBRARY_SEARCH_SYSTEM32) + /* filename may be be in CP_ACP */ + if (!name_w) + return LoadLibraryExA(name, NULL, LOAD_FLAGS); + module = LoadLibraryExW(name_w, NULL, LOAD_FLAGS); +#undef LOAD_FLAGS #endif + av_free(name_w); + return module; } #define dlopen(name, flags) win32_dlopen(name) #define dlclose FreeLibrary diff --git a/libavcodec/mf_utils.h b/libavcodec/mf_utils.h index 3b12344f3e..aebfb9ad21 100644 --- a/libavcodec/mf_utils.h +++ b/libavcodec/mf_utils.h @@ -29,6 +29,7 @@ // mf*.h headers below indirectly include strmif.h.) #include #else +#define NO_DSHOW_STRSAFE #include // Older versions of mingw-w64 need codecapi.h explicitly included, while newer // ones include it implicitly from dshow.h (via uuids.h). From patchwork Sun Jun 19 11:40:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nil Admirari X-Patchwork-Id: 36338 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1a22:b0:84:42e0:ad30 with SMTP id cj34csp1099968pzb; Sun, 19 Jun 2022 04:41:49 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vZ7ntuG5NpguI1dfYGAC79HMm35GXxC/1wYV6omkT1UxpDY92zjMHYmaTMyt2Z95sCpj8k X-Received: by 2002:a17:907:7b8a:b0:707:59d4:14a3 with SMTP id ne10-20020a1709077b8a00b0070759d414a3mr16680893ejc.51.1655638909498; Sun, 19 Jun 2022 04:41:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655638909; cv=none; d=google.com; s=arc-20160816; b=SKjagwRIbWc7ZCX05Bx1Z26GTYfEErJ+S3Wkv2porWs6aKf7zkGWMZQRcFMp7rV7Yf XI/LN+2qoHLr/5OAnce0cT/M0eKKbWkX8WUFc02vi3JSA38lWi4A61YZvAgqFiESoLyh /aS62zVDcb6UaA9oblSc4ovCcH8wXUmJxOqd+REvRLXEoDv2eB8hAdigBAisCYEkpjhG Kzaw8lUBs52oJRXoITLxnzT/hrY/HTYYUzn0lJcPs7WLNu/PNiyedgfLQQY22/IUmndG zLbWCZjLbyKF9fbqLhc6UKRSDmZblezG4BNWdD/oxjrLLWTvfURq46Nrk7XB245BcFdp IKig== 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=hbjgWV34Vkcxwhz2hdDHwD5+6GyuRhhqfdJWXAFq6Zk=; b=fVXt1W4CBVt/pD/2Ja4uP6welAf4eptIGR38gDE8CQHYRCdep40iWuN8HeFzNfcoCP MwUpkYbuFdJdLLVBPkSjhPb91cs7UTxpQHwk3G2I6/aTNXP0jSGFFC9xSkmGSl2URbLQ /AUCwFMtsHsAJfP462mDysBQC1pEyf2Dw8mpeZ9T+4fmkpNUxd8M0YKFrBVUj5OzKvp7 3ofGHTRE5csnstO09YmggzxQ4+NyDb9xPOIab8pjdfE0KukA4cozNSHOcAEd3Bzp/EkL daeeAorv/61mTKexLxNFJNLtA8kSSrp+UBBGOAti8huOhhGiZ1mTEjvsav9/FGjPk7Dl gXdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@mailo.com header.s=mailo header.b="ijc/nOJY"; 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 b12-20020a056402278c00b00425992205e5si7305448ede.346.2022.06.19.04.41.49; Sun, 19 Jun 2022 04:41:49 -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="ijc/nOJY"; 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 E72B668B5BB; Sun, 19 Jun 2022 14:41:19 +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 ECD3C68B366 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=1655638867; bh=SxNCZIL6pwgCEs805VF+XDCzuxaYOZAuHyXcbRuZz4E=; h=X-EA-Auth:From:To:Subject:Date:Message-Id:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding; b=ijc/nOJYKx7ojKsLEHzSD8qTEnbWrDP3DZSVuAixVocDcMtgHahq12KhPDYw7as2q 0eJkq5snCwV8AnGWW5Z0kMjdbKUIUV3WeJX9/4rZjo7XfEYovmDW9PJYwmdck+WB7F mAqEAhHO2ZnXI0XeCO5+cm5KyuvnHG5/d0YHa+lY= 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:07 +0200 (CEST) X-EA-Auth: u+xZLauyzUvirfXX2VDwaOuLLWxWNJuzu0eznc59XAtXoy26c7mM7xdF8KrKiwSYTzEIz4kItN+kiRltrrKYdqe37aOstvfItjmFbEQEW1E= From: Nil Admirari To: ffmpeg-devel@ffmpeg.org Date: Sun, 19 Jun 2022 14:40:54 +0300 Message-Id: <20220619114056.5582-3-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 3/5] fftools: Remove MAX_PATH limit and switch to UTF-8 versions of fopen() and 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: KeK1D9D3K4EL --- fftools/cmdutils.c | 53 +++++++++++++++++++++++++++++++++----------- fftools/ffmpeg_opt.c | 9 ++++++-- 2 files changed, 47 insertions(+), 15 deletions(-) diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index 5d7cdc3e10..69a6f54ea3 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -39,6 +39,7 @@ #include "libavutil/avstring.h" #include "libavutil/channel_layout.h" #include "libavutil/display.h" +#include "libavutil/getenv_utf8.h" #include "libavutil/mathematics.h" #include "libavutil/imgutils.h" #include "libavutil/libm.h" @@ -47,9 +48,11 @@ #include "libavutil/dict.h" #include "libavutil/opt.h" #include "cmdutils.h" +#include "fopen_utf8.h" #include "opt_common.h" #ifdef _WIN32 #include +#include "compat/w32dlfcn.h" #endif AVDictionary *sws_dict; @@ -465,7 +468,7 @@ static void check_options(const OptionDef *po) void parse_loglevel(int argc, char **argv, const OptionDef *options) { int idx = locate_option(argc, argv, options, "loglevel"); - const char *env; + char *env; check_options(options); @@ -474,7 +477,8 @@ void parse_loglevel(int argc, char **argv, const OptionDef *options) if (idx && argv[idx + 1]) opt_loglevel(NULL, "loglevel", argv[idx + 1]); idx = locate_option(argc, argv, options, "report"); - if ((env = getenv("FFREPORT")) || idx) { + env = getenv_utf8("FFREPORT"); + if (env || idx) { FILE *report_file = NULL; init_report(env, &report_file); if (report_file) { @@ -487,6 +491,7 @@ void parse_loglevel(int argc, char **argv, const OptionDef *options) fflush(report_file); } } + freeenv_utf8(env); idx = locate_option(argc, argv, options, "hide_banner"); if (idx) hide_banner = 1; @@ -812,28 +817,45 @@ FILE *get_preset_file(char *filename, size_t filename_size, { FILE *f = NULL; int i; - const char *base[3] = { getenv("FFMPEG_DATADIR"), - getenv("HOME"), +#if HAVE_GETMODULEHANDLE && defined(_WIN32) + char *datadir = NULL; +#endif + char *env_home = getenv_utf8("HOME"); + char *env_ffmpeg_datadir = getenv_utf8("FFMPEG_DATADIR"); + const char *base[3] = { env_home, + env_ffmpeg_datadir, FFMPEG_DATADIR, }; if (is_path) { av_strlcpy(filename, preset_name, filename_size); - f = fopen(filename, "r"); + f = fopen_utf8(filename, "r"); } else { #if HAVE_GETMODULEHANDLE && defined(_WIN32) - char datadir[MAX_PATH], *ls; + wchar_t *datadir_w = get_module_filename(NULL); base[2] = NULL; - if (GetModuleFileNameA(GetModuleHandleA(NULL), datadir, sizeof(datadir) - 1)) + if (wchartoutf8(datadir_w, &datadir)) + datadir = NULL; + av_free(datadir_w); + + if (datadir) { - for (ls = datadir; ls < datadir + strlen(datadir); ls++) + char *ls; + for (ls = datadir; *ls; ls++) if (*ls == '\\') *ls = '/'; if (ls = strrchr(datadir, '/')) { - *ls = 0; - strncat(datadir, "/ffpresets", sizeof(datadir) - 1 - strlen(datadir)); - base[2] = datadir; + ptrdiff_t datadir_len = ls - datadir; + size_t desired_size = datadir_len + strlen("/ffpresets") + 1; + char *new_datadir = av_realloc_array( + datadir, desired_size, sizeof *datadir); + if (new_datadir) { + datadir = new_datadir; + datadir[datadir_len] = 0; + strncat(datadir, "/ffpresets", desired_size - 1 - datadir_len); + base[2] = datadir; + } } } #endif @@ -842,17 +864,22 @@ FILE *get_preset_file(char *filename, size_t filename_size, continue; snprintf(filename, filename_size, "%s%s/%s.ffpreset", base[i], i != 1 ? "" : "/.ffmpeg", preset_name); - f = fopen(filename, "r"); + f = fopen_utf8(filename, "r"); if (!f && codec_name) { snprintf(filename, filename_size, "%s%s/%s-%s.ffpreset", base[i], i != 1 ? "" : "/.ffmpeg", codec_name, preset_name); - f = fopen(filename, "r"); + f = fopen_utf8(filename, "r"); } } } +#if HAVE_GETMODULEHANDLE && defined(_WIN32) + av_free(datadir); +#endif + freeenv_utf8(env_ffmpeg_datadir); + freeenv_utf8(env_home); return f; } diff --git a/fftools/ffmpeg_opt.c b/fftools/ffmpeg_opt.c index 398067da96..e08455478f 100644 --- a/fftools/ffmpeg_opt.c +++ b/fftools/ffmpeg_opt.c @@ -44,6 +44,7 @@ #include "libavutil/avutil.h" #include "libavutil/bprint.h" #include "libavutil/channel_layout.h" +#include "libavutil/getenv_utf8.h" #include "libavutil/intreadwrite.h" #include "libavutil/fifo.h" #include "libavutil/mathematics.h" @@ -1402,8 +1403,10 @@ static int get_preset_file_2(const char *preset_name, const char *codec_name, AV { int i, ret = -1; char filename[1000]; - const char *base[3] = { getenv("AVCONV_DATADIR"), - getenv("HOME"), + char *env_avconv_datadir = getenv_utf8("AVCONV_DATADIR"); + char *env_home = getenv_utf8("HOME"); + const char *base[3] = { env_avconv_datadir, + env_home, AVCONV_DATADIR, }; @@ -1421,6 +1424,8 @@ static int get_preset_file_2(const char *preset_name, const char *codec_name, AV ret = avio_open2(s, filename, AVIO_FLAG_READ, &int_cb, NULL); } } + freeenv_utf8(env_home); + freeenv_utf8(env_avconv_datadir); return ret; } 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); From patchwork Sun Jun 19 11:40:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nil Admirari X-Patchwork-Id: 36335 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:1a22:b0:84:42e0:ad30 with SMTP id cj34csp1099808pzb; Sun, 19 Jun 2022 04:41:21 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uA4u83EdEfFiDgMcYNzLVnPjTjwWMvXulqqsjbanFTyUznNyNGmLQ48SrHbHX34wV/ceFk X-Received: by 2002:a17:907:6d0a:b0:722:b0b5:be69 with SMTP id sa10-20020a1709076d0a00b00722b0b5be69mr2000644ejc.76.1655638881133; Sun, 19 Jun 2022 04:41:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655638881; cv=none; d=google.com; s=arc-20160816; b=C53kLwDnKa9gzXN3YZivaGAOSEP1wv3533sBThIzjvXqFiYBpo00BP0tN6Bhc4gJs7 pCg+0ZyQYinAsg90ioB4ctHwRz/Mrs03IoN3Qery26xgCvzDTPr6+B/QlE47wTUS8ZpB he1WijI3AQy7Z26O8Ty7tlD8vjoFh1ReT16988g88qlsc0hzlSK6CiSe/luVHzqlLnz4 EABx5cKTQi8dCU2qh+j7b4d5kIhKEc8MlqNWyp90/fIaoqIMUEbUcV84dDLAw+9C/BMK OZJa3UgqSRuyoDYxQbzu2t99KaDfZ/oJHGh43pedO5upxThAIiCKuIlO0IEvwZ1qEfQt DbYg== 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=tG6rKQEsTne7YMtGMREEGA18mFfshX0JCuYQ61Ugf/E=; b=d/R3ZhN+ebEdZ2ERKP47+mvywQN3nAJOpeP/18Ii1aNJInRQT7FztUsw3R+Px5XV5g 4Lou8XXNzPZTcvGKK5J7pbSLLbZaHCgaVLgvblw8IrbE8ysaX0REEIVZkvnIi9S2FhqH ielv3JI4Lr23p71h3tUBwV14mRhgN7vpPwfGrQiRxINuJxpjfIM4gB2zFJFQmC9veH1Z rmAA+z/9bbPaygPG99+mzqkO9+WTdSw+7xOMfjdI/Ku1XI2tcEqjo+lrC81/QYUnCKUI ok//KZ9jMmLpGFCtbeWHZghnUpG2HRt21K5R9ncX8TdHo9j3gw106JW9oLRpn4q0x7Ih OAIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@mailo.com header.s=mailo header.b=b86Z2IWL; 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 n19-20020a17090673d300b006fead2c3278si8911011ejl.192.2022.06.19.04.41.20; Sun, 19 Jun 2022 04:41:21 -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=b86Z2IWL; 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 3288E68B3A7; Sun, 19 Jun 2022 14:41:17 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from msg-4.mailo.com (ip-15.mailobj.net [213.182.54.15]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id E5F9668B333 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=1655638869; bh=UKkXBovxyvp8LXhqE7X1COXrX6zLrOEIMYq1dnHDybY=; h=X-EA-Auth:From:To:Subject:Date:Message-Id:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding; b=b86Z2IWL7yurgXpQw9ObowvXe4t0k57E3w+RmNScHVnR1Z5FQ5GGmPJXBDpitJUSO HertusCgrH9lwb5JNU0JmnXZtHsJCJy207RpO65jR+Q2m4g8DwCbXu4/ldnWdyOLo4 RhyGg0Q8y/NmNFmkNrVZkn+aSZwbRczgSAAIAUPo= 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:09 +0200 (CEST) X-EA-Auth: kqwrDJXfybnY8pr35MHgWVtPmZP9+B2frAiyeJKjlqBigYemEJ72W7g5VVTsNVVT3T2DUTHTqc2SaKPwwo35jqGUAmeienwgD7SmhIz/hp4= From: Nil Admirari To: ffmpeg-devel@ffmpeg.org Date: Sun, 19 Jun 2022 14:40:56 +0300 Message-Id: <20220619114056.5582-5-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 5/5] libavfilter/vf_frei0r.c: 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: pL/hVl6AT291 --- libavfilter/vf_frei0r.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/libavfilter/vf_frei0r.c b/libavfilter/vf_frei0r.c index f11ae6e55c..c3176ea1f7 100644 --- a/libavfilter/vf_frei0r.c +++ b/libavfilter/vf_frei0r.c @@ -31,6 +31,7 @@ #include "libavutil/avstring.h" #include "libavutil/common.h" #include "libavutil/eval.h" +#include "libavutil/getenv_utf8.h" #include "libavutil/imgutils.h" #include "libavutil/internal.h" #include "libavutil/mathematics.h" @@ -188,7 +189,7 @@ static av_cold int frei0r_init(AVFilterContext *ctx, f0r_init_f f0r_init; f0r_get_plugin_info_f f0r_get_plugin_info; f0r_plugin_info_t *pi; - char *path; + char *path, *env_frei0r_path; int ret = 0; int i; static const char* const frei0r_pathlist[] = { @@ -204,7 +205,10 @@ static av_cold int frei0r_init(AVFilterContext *ctx, } /* see: http://frei0r.dyne.org/codedoc/html/group__pluglocations.html */ - if ((path = av_strdup(getenv("FREI0R_PATH")))) { + env_frei0r_path = getenv_utf8("FREI0R_PATH"); + path = av_strdup(env_frei0r_path); + freeenv_utf8(env_frei0r_path); + if (path) { #ifdef _WIN32 const char *separator = ";"; #else @@ -231,12 +235,17 @@ static av_cold int frei0r_init(AVFilterContext *ctx, if (ret < 0) return ret; } - if (!s->dl_handle && (path = getenv("HOME"))) { + if (!s->dl_handle && (path = getenv_utf8("HOME"))) { char *prefix = av_asprintf("%s/.frei0r-1/lib/", path); - if (!prefix) - return AVERROR(ENOMEM); + if (!prefix) { + ret = AVERROR(ENOMEM); + goto home_path_end; + } ret = load_path(ctx, &s->dl_handle, prefix, dl_name); av_free(prefix); + + home_path_end: + freeenv_utf8(path); if (ret < 0) return ret; }