[vlc-commits] [Git][videolan/vlc][3.0.x] 2 commits: contrib: ffmpeg: don't rely on MAX_PATH for Windows DLL loading
Steve Lhomme (@robUx4)
gitlab at videolan.org
Sat Nov 9 17:19:35 UTC 2024
Steve Lhomme pushed to branch 3.0.x at VideoLAN / VLC
Commits:
6acdc80b by Steve Lhomme at 2024-11-09T15:51:32+00:00
contrib: ffmpeg: don't rely on MAX_PATH for Windows DLL loading
It also fixes building with newer UWP toolchains.
Only a small part of the first patch is backported.
- - - - -
2afbbfe5 by Steve Lhomme at 2024-11-09T15:51:32+00:00
contrib: ffmpeg: update to 4.4.5
- - - - -
4 changed files:
- + contrib/src/ffmpeg/0001-Replace-all-occurences-of-av_mallocz_array-by-av_cal.patch
- + contrib/src/ffmpeg/0002-compat-w32dlfcn.h-Remove-MAX_PATH-limit-and-replace-.patch
- contrib/src/ffmpeg/SHA512SUMS
- contrib/src/ffmpeg/rules.mak
Changes:
=====================================
contrib/src/ffmpeg/0001-Replace-all-occurences-of-av_mallocz_array-by-av_cal.patch
=====================================
@@ -0,0 +1,29 @@
+From 1ea365082318f06cd42a8b37dd0c7724b599c821 Mon Sep 17 00:00:00 2001
+From: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
+Date: Tue, 14 Sep 2021 21:31:53 +0200
+Subject: [PATCH] Replace all occurences of av_mallocz_array() by av_calloc()
+
+They do the same.
+
+Reviewed-by: Paul B Mahol <onemda at gmail.com>
+Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt at outlook.com>
+---
+ compat/w32dlfcn.h | 2 +-
+ 131 files changed, 302 insertions(+), 301 deletions(-)
+
+diff --git a/compat/w32dlfcn.h b/compat/w32dlfcn.h
+index c83bdc9333..52a94efafb 100644
+--- a/compat/w32dlfcn.h
++++ b/compat/w32dlfcn.h
+@@ -42,7 +42,7 @@ static inline HMODULE win32_dlopen(const char *name)
+ DWORD pathlen;
+ if (utf8towchar(name, &name_w))
+ goto exit;
+- path = (wchar_t *)av_mallocz_array(MAX_PATH, sizeof(wchar_t));
++ path = (wchar_t *)av_calloc(MAX_PATH, sizeof(wchar_t));
+ // Try local directory first
+ pathlen = GetModuleFileNameW(NULL, path, MAX_PATH);
+ pathlen = wcsrchr(path, '\\') - path;
+--
+2.45.0.windows.1
+
=====================================
contrib/src/ffmpeg/0002-compat-w32dlfcn.h-Remove-MAX_PATH-limit-and-replace-.patch
=====================================
@@ -0,0 +1,171 @@
+From dfa062ed3cae1d7ae3fdc52c7adda09cfc2e29b9 Mon Sep 17 00:00:00 2001
+From: Nil Admirari <nil-admirari at mailo.com>
+Date: Mon, 20 Jun 2022 13:29:58 +0300
+Subject: [PATCH] compat/w32dlfcn.h: Remove MAX_PATH limit and replace
+ LoadLibraryExA with LoadLibraryExW
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Signed-off-by: Martin Storsjö <martin at martin.st>
+---
+ 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 <stdint.h>
++
+ #include <windows.h>
++
+ #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 <icodecapi.h>
+ #else
++#define NO_DSHOW_STRSAFE
+ #include <dshow.h>
+ // Older versions of mingw-w64 need codecapi.h explicitly included, while newer
+ // ones include it implicitly from dshow.h (via uuids.h).
+--
+2.45.0.windows.1
+
=====================================
contrib/src/ffmpeg/SHA512SUMS
=====================================
@@ -1 +1 @@
-253799eccd129dad331db85def5352178ae22303e42af47fc013a6adfd4b60d1e59ff5f9ac6118fe3b403affa56ea1f3ba658042f526a914fba27050c3065daf ffmpeg-4.4.4.tar.xz
+70df4e63ef507a7ec76da34438142499139769728fd5130d9cf48d56c110ec82c3d6a7e6d1622da03c70167fa861d901d016bbe52c21d2b284b8a0d9f30811dc ffmpeg-4.4.5.tar.xz
=====================================
contrib/src/ffmpeg/rules.mak
=====================================
@@ -7,7 +7,7 @@
ifndef USE_LIBAV
FFMPEG_HASH=71fb6132637a2a430375c24afc381fff8b854fe7
FFMPEG_MAJVERSION := 4.4
-FFMPEG_REVISION := 4
+FFMPEG_REVISION := 5
FFMPEG_VERSION := $(FFMPEG_MAJVERSION).$(FFMPEG_REVISION)
FFMPEG_BRANCH=release/$(FFMPEG_MAJVERSION)
FFMPEG_URL := https://ffmpeg.org/releases/ffmpeg-$(FFMPEG_VERSION).tar.xz
@@ -253,6 +253,8 @@ ifdef USE_FFMPEG
$(APPLY) $(SRC)/ffmpeg/0001-bring-back-XP-support.patch
$(APPLY) $(SRC)/ffmpeg/0001-avcodec-vp9-Do-not-destroy-uninitialized-mutexes-con.patch
$(APPLY) $(SRC)/ffmpeg/0001-dxva2_hevc-don-t-use-frames-as-reference-if-they-are.patch
+ $(APPLY) $(SRC)/ffmpeg/0001-Replace-all-occurences-of-av_mallocz_array-by-av_cal.patch
+ $(APPLY) $(SRC)/ffmpeg/0002-compat-w32dlfcn.h-Remove-MAX_PATH-limit-and-replace-.patch
endif
ifdef USE_LIBAV
$(APPLY) $(SRC)/ffmpeg/libav_gsm.patch
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/075e8d6968bf8b2e6118be90626da9918ec70296...2afbbfe5cd61641cc88a332fd7f8c4bfdea5d9db
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/075e8d6968bf8b2e6118be90626da9918ec70296...2afbbfe5cd61641cc88a332fd7f8c4bfdea5d9db
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list