From patchwork Thu Jun 9 19:04:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: nihil-admirari X-Patchwork-Id: 36098 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6914:b0:82:6b11:2509 with SMTP id q20csp542461pzj; Thu, 9 Jun 2022 12:04:51 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyAfVBFil3HWUhipL1fys1wMjREIyn96e4eoNy5BZn9t5kYHqSWCLVJKKRLvKof4SdPVbbv X-Received: by 2002:a50:ff04:0:b0:431:6a31:f19e with SMTP id a4-20020a50ff04000000b004316a31f19emr89577edu.89.1654801491115; Thu, 09 Jun 2022 12:04:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654801491; cv=none; d=google.com; s=arc-20160816; b=FATKmo/4u57jBf9DnTyuufq6rOZ2RaoVeJDG6ZnQwXvuY+FkTeah5c9BvAOQunwvfD 6lu3DNZaX2xIR3/c4auvOJLKjLJ5uNje44Tcf2cYjsgZk7e9y3dYKOfrKeduTzgnaTP7 scDLzUpjCIC6BrTx/i1rWV2TXEfCaL2NxNOxgBnC/SI6g7Ky4Xj9KUa4VVfw6Ln43xuO jchYiFiiwUP2WwkHnBbxazQ8jNkCWxWThWRKb6NbmNBngFbi91kYkqkprote4qMBmP+P uUu1Aus5XB1Eieq8VzODcL7vQPjexXnabMu2LOoTOskNafDzZCmrbER7ez3YBqIDJljZ wRyQ== 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=VuA6WRvdAU3Xj8j/3F8qDvHwlT74AdSNinRr9cCpUKw=; b=xmPFPpcKQ6Vqgf+297mxwhbGGTGz5z5WLq3+CVJ4Kd6Fre+v0uJMAp5xhFykTORNFn 6zHTkowwi3GVr/tiRLKRi1ghcD3C0MpjV5gqN5EuONvTP6aQnTbmav7F8E53GFF+B9N/ jMr+rnHV1rM6b0CkKu8flmbqH4VH2l+Hq6ZxcTaCg3N3MJm6BDqjzsy/gSo5uqbFEhin KWp9V0jyzidMyCWQpK2D8hBxb+7mmCJmEa8sjLQCWIOJPWsztLKyZv+vA3tJtbmqaz6C PqcUaGd6VAr+pQuLzduanuG3GBTljNPZyEoUTX5wqNx/5XCpBjwjOIa9fL37AjV0J5uT mrLQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@mailo.com header.s=mailo header.b=cOOVUoei; 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 k2-20020aa7d8c2000000b0042dc274de99si4217995eds.232.2022.06.09.12.04.50; Thu, 09 Jun 2022 12:04:51 -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=cOOVUoei; 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 43D1468B7AB; Thu, 9 Jun 2022 22:04:25 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from msg-1.mailo.com (msg-1.mailo.com [213.182.54.11]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 061B868B760 for ; Thu, 9 Jun 2022 22:04:15 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailo.com; s=mailo; t=1654801453; bh=iU5AFvt7nf9q02CxCI6FGFXWnl6IDaX9y4aPPz7wogg=; h=X-EA-Auth:From:To:Subject:Date:Message-Id:X-Mailer:MIME-Version: Content-Transfer-Encoding; b=cOOVUoeihCYwOTTbORD4i2vkiiZUgzG3iBezLx4nMTr1yFt/rsJAy1LM9R+1P0Peb P6coz4KEVU8xheFSkmT6TSUhhfkD1N+9l6gY/yB1An5JDRAnnJ/qwWqWDQF9jhJZzF U0zCXZIyLwt0htdWROBYhXyTvtQjB9WQwsdx2qHc= Received: by b-1.in.mailobj.net [192.168.90.11] with ESMTP via ip-206.mailobj.net [213.182.55.206] Thu, 9 Jun 2022 21:04:13 +0200 (CEST) X-EA-Auth: G8rDSMTXPjyDoizMvMEp7hsUj1dapxTmNNR0U/4fK8/slUCMQovrx/YoykOm9SDF5b3QS0ECcAKpXxImtfyVp3kGqBgGyyMJRWvlnp6pAG8= From: Nil Admirari To: ffmpeg-devel@ffmpeg.org Date: Thu, 9 Jun 2022 22:04:03 +0300 Message-Id: <20220609190406.6339-1-nil-admirari@mailo.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v13 1/4] libavutil/wchar_filename.h: Add whcartoutf8, wchartoansi and utf8toansi 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: wqEWs8EphUYc These functions are going to be used in libavformat/avisynth.c and fftools/cmdutils.c to remove MAX_PATH limit. --- libavutil/wchar_filename.h | 51 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/libavutil/wchar_filename.h b/libavutil/wchar_filename.h index f36d9df..90f6a53 100644 --- a/libavutil/wchar_filename.h +++ b/libavutil/wchar_filename.h @@ -41,6 +41,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 ? MB_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_calloc(num_chars, sizeof(char)); + 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 Thu Jun 9 19:04:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: nihil-admirari X-Patchwork-Id: 36095 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6914:b0:82:6b11:2509 with SMTP id q20csp542389pzj; Thu, 9 Jun 2022 12:04:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzP30NZN+2GWfPTp07GYDCyUySKS8BKVp8CDVD+mng8qg6mBmd/fo0kC5t1GCTT80AtRibc X-Received: by 2002:a17:906:7a5e:b0:6fe:d93d:21a3 with SMTP id i30-20020a1709067a5e00b006fed93d21a3mr4164486ejo.596.1654801483873; Thu, 09 Jun 2022 12:04:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654801483; cv=none; d=google.com; s=arc-20160816; b=e8LUP4n0A08ZK6770y4ebJDJnhLlhMK8PLsCyekoAtvi1uaQTwrduZvU5TLOPLgngA b5VgZzcc0lGjd1K8t13tePB915Lmr6CZp09UUwr+nau3edJ5LgfR8QT+6aADYHrMeZ1X EjE+c9PLkcLfEQO6gT1ZgasfaMoCpHX2YnwxeD66Ar+Htz60kwRQK49Md2D29lF5kyyc DLgMQKvNp76jvRr50ekj8nzWS3c2IxQaPGwHisGL2weAxpqzmvZ7xWD1MO9HYPBZsFiY QKKaIiIIoAnyxowYZjHu6yEznXgqYYz55C/cwpZrKFW4bWo00XYEvFwawHwPV6+C+YbI K5+A== 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=aYmxMYrs3hJCZadOTVhZJFh48qqDpc5LXl/qTcjn3VA=; b=zvDxbZPr2oqqQA4P19tW8kS6xMyu+X70cqcB/qNptI4VdC5ivTYWffiWjcT5TUBWB1 Lah22uzHgfbx04Row9peeMOkVGfDIh/lnC0C2o2P+G6rVivC4laOThAsFQqrhUdDGdVt 79jb9Lv0VYVcYfsiYuu5CvyEvhukuS1arBUi8Js9YL4nX+NlnfenG/0JlK2aqTUeB7Ow VvNNkuwb+xTa6exKqY1sjSAqy9HWubTAohNYfPKcENN2XbC8zktmu7DE5sOyR/8aZkWD wF4XedGJsnO8crX3k9dpVfqkbwBjfStAbiBNTJJFN4QC2iRbPYak8A30adEOa3s+pE4r ttgg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@mailo.com header.s=mailo header.b=nr9xy4dt; 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 qw29-20020a1709066a1d00b0071114e6de39si4420717ejc.679.2022.06.09.12.04.41; Thu, 09 Jun 2022 12:04:43 -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=nr9xy4dt; 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 5970668B7A2; Thu, 9 Jun 2022 22:04:24 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from msg-1.mailo.com (msg-1.mailo.com [213.182.54.11]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 05B6568B759 for ; Thu, 9 Jun 2022 22:04:15 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailo.com; s=mailo; t=1654801453; bh=mpaN5hOKH8Aw9kq9HUTODy73YmSm0a0YmTPV45fwKD0=; h=X-EA-Auth:From:To:Subject:Date:Message-Id:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding; b=nr9xy4dtLORASy7VundNA/sm6fiMpXc8Od2zBIQXENwxhk5BbnsFGSTI4n7wH8AvS WpGELjm8knw1uoiBecY4iBhRjEMP9+6Ud9C2lr7nEr8zQ9VoVaouA74g4b4ir9XNS+ LlYcbYwOuW6k0crhRLnPIfCaLatW9vyJ2wmzrRRU= Received: by b-1.in.mailobj.net [192.168.90.11] with ESMTP via ip-206.mailobj.net [213.182.55.206] Thu, 9 Jun 2022 21:04:13 +0200 (CEST) X-EA-Auth: blORkXPIBqbSOElMdWa8dNcAwbkRmgNPJ+dprqOlgY+ZdoaO75981Zuf3pmXDHPwuVrW6SBRgh4S/RLZCYgAqM+rpKFdVFBCfYQ1mABRjdU= From: Nil Admirari To: ffmpeg-devel@ffmpeg.org Date: Thu, 9 Jun 2022 22:04:04 +0300 Message-Id: <20220609190406.6339-2-nil-admirari@mailo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220609190406.6339-1-nil-admirari@mailo.com> References: <20220609190406.6339-1-nil-admirari@mailo.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v13 2/4] libavformat/avisynth.c: Remove MAX_PATH limit 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: t1+v+6fK0wuN --- libavformat/avisynth.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/libavformat/avisynth.c b/libavformat/avisynth.c index 8ba2bde..f7bea8c 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 @@ -810,8 +811,7 @@ static int avisynth_open_file(AVFormatContext *s) AVS_Value arg, val; int ret; #ifdef _WIN32 - char filename_ansi[MAX_PATH * 4]; - wchar_t filename_wc[MAX_PATH * 4]; + char *filename_ansi = NULL; #endif if (ret = avisynth_context_create(s)) @@ -819,10 +819,12 @@ static int avisynth_open_file(AVFormatContext *s) #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); + if (utf8toansi(s->url, &filename_ansi)) { + ret = AVERROR_UNKNOWN; + goto fail; + } arg = avs_new_value_string(filename_ansi); + av_free(filename_ansi); #else arg = avs_new_value_string(s->url); #endif From patchwork Thu Jun 9 19:04:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: nihil-admirari X-Patchwork-Id: 36097 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6914:b0:82:6b11:2509 with SMTP id q20csp542313pzj; Thu, 9 Jun 2022 12:04:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxBbrl3deoeyD7QZxYBiThiFEXUPtRxQ6ZWtzJqcBBu/jAWfsFPmFsvzqeUUXLanw7EkTTZ X-Received: by 2002:a17:906:7a0b:b0:712:e5:6bbe with SMTP id d11-20020a1709067a0b00b0071200e56bbemr5506492ejo.640.1654801474764; Thu, 09 Jun 2022 12:04:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654801474; cv=none; d=google.com; s=arc-20160816; b=wMbe8CtH3eGEgnwIRCen0DeNApm8MvbaHbQxJIeph3HRV09ESraIcAat8PY+7y0nHG TqL96YTbsyR7d9ipcAGXewDyVcL0WLQGD8YUVuijM7n1wh1L5qh+xr89/hyU1IykUc4L ehiL2Mcbjwb6J5xrmuJodNah7x7NKU3s6fml5kE1hE4JtJZD2hYnRDUuv/18ClCRIm5v 8t01faN6Yma0P4vJzB7bfRQjGw9UYhbMsaZ1L0htkW4qi43fPkOXGbNmtKPmCk2aM9xf 4DRUVW5DzBhZZ8StEd3RdnKLfp+oqyyrMcBamZsgTNR9wXcM+k/GW7kxQBRhBWDcAsD2 559w== 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=kchZNjAoPI1D76eQGAQAHeEZQbrsmpYFNuq+LvY8BCw=; b=VN2gD1c0OeGWpLQM2sbDG79/slisozFp7EM6Csn6xZGycjAP+cdqpTiEmrmxg45meD r5EabH+3XEk28O/F1fKoRxmxRysX1buBtlnjH8cLuS+jAq+yqus2Yuhp72/gVH8yeFia UyVJMlHlzRvb5xWU5t22wmBppguV14C5E5Ow79femBHbEuBJUAQFNsVClYs6Diy0vMWt D5iH9UEX28HlMzzuAkigX/UMb4s+eieDnZhrzX6bVaOmfixZigj03E3lAWDwdIceGX+n he5RfB0trFXfjsSpZ1ZfMqA4OzD7w2tvy8locuzq4W0/pG8c+CvgiMDbpIa39/ERigTa yqgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@mailo.com header.s=mailo header.b=GOlci+DG; 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 b9-20020a056402084900b0042aed1df374si2334881edz.308.2022.06.09.12.04.33; Thu, 09 Jun 2022 12:04:34 -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=GOlci+DG; 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 6087F68B79A; Thu, 9 Jun 2022 22:04:23 +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 DD0A268B73D for ; Thu, 9 Jun 2022 22:04:15 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailo.com; s=mailo; t=1654801454; bh=2cGYK/mQD9DIV+tlqEuWkbmDiY38A53odPccVCTf4Lk=; h=X-EA-Auth:From:To:Subject:Date:Message-Id:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding; b=GOlci+DGEK0Xm4rbfN187Q+v9269zQFoNtI3E7ptoZ75CVEDi5P6gpG1mGbOCg81Q mxUd7Wkw+Qux41sFT8mE2KvpEEfSbOLYD3xeyYmBpnnYJxC90wcxXJS7gcbooesZIv awvdUOtzaOIKSzhnUKETVtYTiKCJT+Nm9ZDNi2c4= Received: by b-1.in.mailobj.net [192.168.90.11] with ESMTP via ip-206.mailobj.net [213.182.55.206] Thu, 9 Jun 2022 21:04:14 +0200 (CEST) X-EA-Auth: tBqrC0VmZOZ09bV1lHZpKRaraT1ZKMUL9TEFMhjGcxwg/65bxcuqahW2xWlY9DKA2FN73YDVgeYOW+QE1SlNnQIAXztONlrkhYHLDsdAoX4= From: Nil Admirari To: ffmpeg-devel@ffmpeg.org Date: Thu, 9 Jun 2022 22:04:05 +0300 Message-Id: <20220609190406.6339-3-nil-admirari@mailo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220609190406.6339-1-nil-admirari@mailo.com> References: <20220609190406.6339-1-nil-admirari@mailo.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v13 3/4] 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: KhZiR0qbRfdf --- compat/w32dlfcn.h | 80 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 64 insertions(+), 16 deletions(-) diff --git a/compat/w32dlfcn.h b/compat/w32dlfcn.h index 52a94ef..6b0dd7d 100644 --- a/compat/w32dlfcn.h +++ b/compat/w32dlfcn.h @@ -22,9 +22,31 @@ #ifdef _WIN32 #include #include "config.h" -#if (_WIN32_WINNT < 0x0602) || HAVE_WINRT #include "libavutil/wchar_filename.h" -#endif + +static inline wchar_t *get_module_filename(HMODULE module) +{ + wchar_t *path = NULL, *new_path = NULL; + DWORD path_size = 0, path_len = 0; + + do { + path_size = path_size ? 2 * path_size : MAX_PATH; + new_path = av_realloc_array(path, path_size, sizeof *path); + if (!new_path) { + av_free(path); + return NULL; + } + path = new_path; + path_len = GetModuleFileNameW(module, path, path_size); + } while (path_len && path_size <= 32768 && 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 +56,53 @@ */ static inline HMODULE win32_dlopen(const char *name) { + wchar_t *name_w = NULL; + if (utf8towchar(name, &name_w)) + name_w = NULL; #if _WIN32_WINNT < 0x0602 // Need to 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 = NULL; + 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; - path[pathlen] = '\\'; + new_path = wcsrchr(path, '\\'); + if (!new_path) + goto exit; + 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 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 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,15 +119,17 @@ 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; #else - return LoadLibraryExA(name, NULL, LOAD_LIBRARY_SEARCH_APPLICATION_DIR | LOAD_LIBRARY_SEARCH_SYSTEM32); + /* filename may be be in CP_ACP */ + if (!name_w) + return LoadLibraryExA(name, NULL, LOAD_LIBRARY_SEARCH_APPLICATION_DIR | LOAD_LIBRARY_SEARCH_SYSTEM32); + return LoadLibraryExW(name_w, NULL, LOAD_LIBRARY_SEARCH_APPLICATION_DIR | LOAD_LIBRARY_SEARCH_SYSTEM32); #endif } #define dlopen(name, flags) win32_dlopen(name) From patchwork Thu Jun 9 19:04:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: nihil-admirari X-Patchwork-Id: 36096 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:6914:b0:82:6b11:2509 with SMTP id q20csp542219pzj; Thu, 9 Jun 2022 12:04:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzzXcF3+Z4CeL/d24kWo+eWCg9rPZhoIOvA69CbBWttgRwIHoV3NR7i2pviCDXjLMeuYItS X-Received: by 2002:a05:6402:542:b0:42d:c7d6:4121 with SMTP id i2-20020a056402054200b0042dc7d64121mr46121128edx.302.1654801465445; Thu, 09 Jun 2022 12:04:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654801465; cv=none; d=google.com; s=arc-20160816; b=uy8Dx2EnrkhN3ehFgwSDKuyI9peETAdAONt+1qOmw5tVRFAnVmSQ4l4LZdEveD+EVd XwXR8cYBl/XeWC7r32/rmHdP++z2DPlvCZ7HJzo4xoTkGnmNw8C65WgakxCTr9j7CETr Pcgb1vPThQJmMUpeM5PdVYkUQFuQncQzRuYzQpJzvXzAslB+5zrKU/HVQCpzqpYclSk4 fb5589CHv+cWwl9zRSwjFPC7WbfpI3eSL5ptj7AnKEOq/6ciZiGM97BmD8lY+Awr9ujQ CRCFbMIkRvveZUVLewS7AaKUeFnWXjskR3l8f6EGp3suWym4KIcfqI4AMsygvhF1FsZU J3Fw== 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=R0CfGy6UTozgz6Pxl8r7vUtEqtVdeiC6dcYzyZroIdg=; b=Pl/85h+SLxKSOU+eAAY2bNFgPlVn1xiYcqrBKmhM50b6SgMm+Q8qK01434Mz8lIEcB jRtGvEW9s5M4jcmk0PyH2IqjDCIjpyc41djZRSK1sV7vWblIbw4q/RbgZbx17P2lkYE0 JRAtv4cwtjB4LVKoIDcHEvh32hkc/2wOQDaPlbp2V9bJQDkG3GubPOBfmgthqDQ6auJC IAyFidRNru1P2VILMaQTDZhBsAdyymigTa+rEE93W3R7ilSqfC/cbx9StLP1MmcnAGHq 0nfDp13LHkHNojhNfFWhPkUvqXk7+PA6MYnn1g0+hvrpV6xadmJ108Ybf9ao/oO/lmVC kj8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@mailo.com header.s=mailo header.b=KiVM6X6o; 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 n13-20020a05640205cd00b0042aac548ac8si19316106edx.405.2022.06.09.12.04.24; Thu, 09 Jun 2022 12:04:25 -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=KiVM6X6o; 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 7CBA668B759; Thu, 9 Jun 2022 22:04:22 +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 D97A168B583 for ; Thu, 9 Jun 2022 22:04:15 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mailo.com; s=mailo; t=1654801455; bh=Ex0XRnhO+eBaLXd0T9UAKNQ5KIO1V7L41aGOAUt7LFw=; h=X-EA-Auth:From:To:Subject:Date:Message-Id:X-Mailer:In-Reply-To: References:MIME-Version:Content-Transfer-Encoding; b=KiVM6X6oHCNkNDaAAR8XOzMGyT5NduGT0utvAS8gSpqiw0eiccwHiIRopECN39QCo 48eIDIGJSCU8U6M0NPWZc+LNO0Y91jicYIDLzvcKZrW3uRSMyRpjt7PaBvEH73IgCO wzZRQZdh82VAX/HvthaYk5hc3TyPIFb0lNNrHCm8= Received: by b-1.in.mailobj.net [192.168.90.11] with ESMTP via ip-206.mailobj.net [213.182.55.206] Thu, 9 Jun 2022 21:04:15 +0200 (CEST) X-EA-Auth: fMf3IRd5VoPcE5k3UctEuecs+7RcybiuSd1dkrowzx3iNESWx9m27fGvH/H4zEaTElZ7viVF9LDHBPncGJGWep51Sjq48mYfab+beKIQ6M8= From: Nil Admirari To: ffmpeg-devel@ffmpeg.org Date: Thu, 9 Jun 2022 22:04:06 +0300 Message-Id: <20220609190406.6339-4-nil-admirari@mailo.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220609190406.6339-1-nil-admirari@mailo.com> References: <20220609190406.6339-1-nil-admirari@mailo.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v13 4/4] fftools/cmdutils.c: Remove MAX_PATH limit 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: bCccloVVTZe/ --- fftools/cmdutils.c | 31 +++++++++++++++++++++++++------ 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/fftools/cmdutils.c b/fftools/cmdutils.c index 5d7cdc3..d42bb04 100644 --- a/fftools/cmdutils.c +++ b/fftools/cmdutils.c @@ -50,6 +50,7 @@ #include "opt_common.h" #ifdef _WIN32 #include +#include "compat/w32dlfcn.h" #endif AVDictionary *sws_dict; @@ -812,6 +813,9 @@ FILE *get_preset_file(char *filename, size_t filename_size, { FILE *f = NULL; int i; +#if HAVE_GETMODULEHANDLE && defined(_WIN32) + char *datadir = NULL; +#endif const char *base[3] = { getenv("FFMPEG_DATADIR"), getenv("HOME"), FFMPEG_DATADIR, }; @@ -821,19 +825,31 @@ FILE *get_preset_file(char *filename, size_t filename_size, f = fopen(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 (wchartoansi(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 @@ -853,6 +869,9 @@ FILE *get_preset_file(char *filename, size_t filename_size, } } +#if HAVE_GETMODULEHANDLE && defined(_WIN32) + av_free(datadir); +#endif return f; }