[vlc-commits] [Git][videolan/vlc][master] contrib: medialibrary: import upstream patches

Steve Lhomme (@robUx4) gitlab at videolan.org
Sat Jul 6 17:16:45 UTC 2024



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
d360da6b by Steve Lhomme at 2024-07-06T16:44:22+00:00
contrib: medialibrary: import upstream patches

Fixing wstring usage with NULL strings.

- - - - -


7 changed files:

- + contrib/src/medialibrary/0002-win32-DeviceLister-don-t-use-wchar_t-string-if-they-.patch
- + contrib/src/medialibrary/0003-utils-Directory-don-t-use-wchar_t-string-if-they-are.patch
- + contrib/src/medialibrary/0004-test-common-don-t-use-wchar_t-string-if-they-are-NUL.patch
- + contrib/src/medialibrary/0005-LockFile-don-t-use-char-string-if-they-are-NULL.patch
- + contrib/src/medialibrary/0006-fs-Directory-don-t-use-char-string-if-they-are-NULL.patch
- + contrib/src/medialibrary/0007-utils-Directory-don-t-use-char-string-if-they-are-NU.patch
- contrib/src/medialibrary/rules.mak


Changes:

=====================================
contrib/src/medialibrary/0002-win32-DeviceLister-don-t-use-wchar_t-string-if-they-.patch
=====================================
@@ -0,0 +1,57 @@
+From af536d9421c471b386c1e2f308cc515679f8e26a Mon Sep 17 00:00:00 2001
+From: Steve Lhomme <robux4 at ycbcr.xyz>
+Date: Fri, 28 Jun 2024 07:59:28 +0200
+Subject: [PATCH 2/7] win32: DeviceLister: don't use wchar_t string if they are
+ NULL
+
+---
+ src/filesystem/win32/DeviceLister.cpp | 19 +++++++++++++++----
+ 1 file changed, 15 insertions(+), 4 deletions(-)
+
+diff --git a/src/filesystem/win32/DeviceLister.cpp b/src/filesystem/win32/DeviceLister.cpp
+index 1f8c2a13..f784190c 100644
+--- a/src/filesystem/win32/DeviceLister.cpp
++++ b/src/filesystem/win32/DeviceLister.cpp
+@@ -74,8 +74,13 @@ std::vector<CommonDeviceLister::Device> DeviceLister::networkDevices() const
+             ss << "WNetEnumResource error: #" << GetLastError();
+             throw fs::errors::DeviceListing{ ss.str() };
+         }
+-        std::string mountpoint = charset::FromWide( netResources->lpLocalName ).get();
+-        std::string uuid = charset::FromWide( netResources->lpRemoteName ).get();
++        auto utf8_local = charset::FromWide( netResources->lpLocalName );
++        auto utf8_remote = charset::FromWide( netResources->lpRemoteName );
++        if ( !utf8_local || !utf8_remote )
++            continue;
++
++        std::string mountpoint = utf8_local.get();
++        std::string uuid = utf8_remote.get();
+         devs.emplace_back( std::move( uuid ),
+             std::vector<std::string>{ utils::file::toMrl( mountpoint ) }, true );
+     } while ( true );
+@@ -118,7 +123,10 @@ std::vector<CommonDeviceLister::Device> DeviceLister::localDevices() const
+ 
+         if ( GetVolumePathNamesForVolumeName( volumeName, buffer, buffLength, &buffLength ) == 0 )
+             continue;
+-        std::string mountpoint = charset::FromWide( buffer ).get();
++        auto utf8_buffer = charset::FromWide( buffer );
++        if ( !utf8_buffer )
++            continue;
++        std::string mountpoint = utf8_buffer.get();
+ 
+         // Filter out anything which isn't a removable or fixed drive. We don't care about network
+         // drive here.
+@@ -126,7 +134,10 @@ std::vector<CommonDeviceLister::Device> DeviceLister::localDevices() const
+         if ( type != DRIVE_REMOVABLE && type != DRIVE_FIXED && type != DRIVE_REMOTE )
+             continue;
+ 
+-        std::string uuid =  charset::FromWide( volumeName ).get();
++        auto utf8_volume = charset::FromWide( volumeName );
++        if ( !utf8_volume )
++            continue;
++        std::string uuid =  utf8_volume.get();
+ 
+         LOG_INFO( "Discovered device ", uuid, "; mounted on ", mountpoint, "; removable: ",
+                   type == DRIVE_REMOVABLE ? "yes" : "no" );
+-- 
+2.45.0.windows.1
+


=====================================
contrib/src/medialibrary/0003-utils-Directory-don-t-use-wchar_t-string-if-they-are.patch
=====================================
@@ -0,0 +1,38 @@
+From 9245cc70cbae11d2a5d1d97c9e5f4a5a921119f3 Mon Sep 17 00:00:00 2001
+From: Steve Lhomme <robux4 at ycbcr.xyz>
+Date: Fri, 28 Jun 2024 08:00:14 +0200
+Subject: [PATCH 3/7] utils: Directory: don't use wchar_t string if they are
+ NULL
+
+---
+ src/utils/Directory.cpp | 7 +++++++
+ 1 file changed, 7 insertions(+)
+
+diff --git a/src/utils/Directory.cpp b/src/utils/Directory.cpp
+index a5c3684f..463b0c26 100644
+--- a/src/utils/Directory.cpp
++++ b/src/utils/Directory.cpp
+@@ -104,6 +104,11 @@ std::string toAbsolute( const std::string& path )
+         throw errors::System{ GetLastError(), "Failed to convert to absolute path" };
+     }
+     auto upath = charset::FromWide( buff );
++    if ( !upath )
++    {
++        LOG_ERROR( "Failed to convert ", path, " to UTF8" );
++        throw errors::System{ GetLastError(), "Failed to convert to UTF8" };
++    }
+     return file::toFolderPath( upath.get() );
+ #endif
+ }
+@@ -209,6 +214,8 @@ bool rmdir( std::string path )
+     do
+     {
+         auto file = charset::FromWide( f.cFileName );
++        if ( !file )
++            continue;
+         if ( strcmp( file.get(), "." ) == 0 ||
+              strcmp( file.get(), ".." ) == 0 )
+             continue;
+-- 
+2.45.0.windows.1
+


=====================================
contrib/src/medialibrary/0004-test-common-don-t-use-wchar_t-string-if-they-are-NUL.patch
=====================================
@@ -0,0 +1,25 @@
+From 19b3e069d3485f5bccc2712d9f96da1628800a22 Mon Sep 17 00:00:00 2001
+From: Steve Lhomme <robux4 at ycbcr.xyz>
+Date: Fri, 28 Jun 2024 08:00:31 +0200
+Subject: [PATCH 4/7] test: common: don't use wchar_t string if they are NULL
+
+---
+ test/common/util.h | 2 ++
+ 1 file changed, 2 insertions(+)
+
+diff --git a/test/common/util.h b/test/common/util.h
+index d0ff02ce..79d92fe0 100644
+--- a/test/common/util.h
++++ b/test/common/util.h
+@@ -36,6 +36,8 @@ static inline std::string getTempDir()
+     WCHAR path[MAX_PATH];
+     GetTempPathW( MAX_PATH, path );
+     auto utf8 = medialibrary::charset::FromWide( path );
++    if ( !utf8 )
++        return {};
+     return utf8.get();
+ #else
+     return "/tmp/";
+-- 
+2.45.0.windows.1
+


=====================================
contrib/src/medialibrary/0005-LockFile-don-t-use-char-string-if-they-are-NULL.patch
=====================================
@@ -0,0 +1,26 @@
+From fce5e4d3a7d9cc199dcc530b6f2d2dae0a544aa7 Mon Sep 17 00:00:00 2001
+From: Steve Lhomme <robux4 at ycbcr.xyz>
+Date: Fri, 28 Jun 2024 08:17:23 +0200
+Subject: [PATCH 5/7] LockFile: don't use char string if they are NULL
+
+---
+ src/LockFile.cpp | 3 +++
+ 1 file changed, 3 insertions(+)
+
+diff --git a/src/LockFile.cpp b/src/LockFile.cpp
+index acd65502..75f224dc 100644
+--- a/src/LockFile.cpp
++++ b/src/LockFile.cpp
+@@ -50,6 +50,9 @@ std::unique_ptr<LockFile> LockFile::lock( const std::string& mlFolderPath )
+     Handle handle;
+ #ifdef _WIN32
+     auto wide = charset::ToWide( lockFile.c_str() );
++    if ( !wide )
++        handle = INVALID_HANDLE_VALUE;
++    else
+ # if _WIN32_WINNT >= 0x0602 /* _WIN32_WINNT_WIN8 */
+     handle = CreateFile2(wide.get(), GENERIC_WRITE, 0, CREATE_ALWAYS, NULL);
+ # else
+-- 
+2.45.0.windows.1
+


=====================================
contrib/src/medialibrary/0006-fs-Directory-don-t-use-char-string-if-they-are-NULL.patch
=====================================
@@ -0,0 +1,28 @@
+From 154cccbef7e6be13f9f57d9eeef5eabfb5182a6a Mon Sep 17 00:00:00 2001
+From: Steve Lhomme <robux4 at ycbcr.xyz>
+Date: Fri, 28 Jun 2024 08:17:58 +0200
+Subject: [PATCH 6/7] fs: Directory: don't use char string if they are NULL
+
+---
+ src/filesystem/libvlc/Directory.cpp | 4 +++-
+ 1 file changed, 3 insertions(+), 1 deletion(-)
+
+diff --git a/src/filesystem/libvlc/Directory.cpp b/src/filesystem/libvlc/Directory.cpp
+index 17594ab7..b08813c5 100644
+--- a/src/filesystem/libvlc/Directory.cpp
++++ b/src/filesystem/libvlc/Directory.cpp
+@@ -174,8 +174,10 @@ void Directory::addFile( std::string mrl, fs::IFile::LinkedFileType linkedType,
+ 
+ #ifdef _WIN32
+         /* We can't use _wstat here, see #323 */
++        auto wpath = charset::ToWide( path.c_str() );
+         WIN32_FILE_ATTRIBUTE_DATA attributes;
+-        if ( GetFileAttributesExW( charset::ToWide( path.c_str() ).get(),
++        if ( !wpath ||
++             GetFileAttributesExW( wpath.get(),
+                                    GetFileExInfoStandard, &attributes ) == 0 )
+         {
+             LOG_ERROR( "Failed to get ", path, " attributes" );
+-- 
+2.45.0.windows.1
+


=====================================
contrib/src/medialibrary/0007-utils-Directory-don-t-use-char-string-if-they-are-NU.patch
=====================================
@@ -0,0 +1,61 @@
+From 71eb7e35818a03b0d0dc71ce45ea4ead406e5278 Mon Sep 17 00:00:00 2001
+From: Steve Lhomme <robux4 at ycbcr.xyz>
+Date: Fri, 28 Jun 2024 08:23:47 +0200
+Subject: [PATCH 7/7] utils: Directory: don't use char string if they are NULL
+
+---
+ src/utils/Directory.cpp | 10 ++++++++--
+ 1 file changed, 8 insertions(+), 2 deletions(-)
+
+diff --git a/src/utils/Directory.cpp b/src/utils/Directory.cpp
+index 463b0c26..a0ff15ad 100644
+--- a/src/utils/Directory.cpp
++++ b/src/utils/Directory.cpp
+@@ -73,6 +73,8 @@ bool isDirectory( const std::string& path )
+ {
+ #ifdef _WIN32
+     auto wpath = charset::ToWide( path.c_str() );
++    if ( !wpath )
++        throw errors::System{ GetLastError(), ERR_FS_OBJECT_ACCESS + path };
+     auto attr = GetFileAttributes( wpath.get() );
+     if ( attr == INVALID_FILE_ATTRIBUTES )
+         throw errors::System{ GetLastError(), ERR_FS_OBJECT_ACCESS + path };
+@@ -98,7 +100,7 @@ std::string toAbsolute( const std::string& path )
+ #else
+     wchar_t buff[MAX_PATH];
+     auto wpath = charset::ToWide( path.c_str() );
+-    if ( GetFullPathNameW( wpath.get(), MAX_PATH, buff, nullptr ) == 0 )
++    if ( !wpath || GetFullPathNameW( wpath.get(), MAX_PATH, buff, nullptr ) == 0 )
+     {
+         LOG_ERROR( "Failed to convert ", path, " to absolute path" );
+         throw errors::System{ GetLastError(), "Failed to convert to absolute path" };
+@@ -136,7 +138,7 @@ bool mkdir( const std::string& path )
+             continue;
+         }
+         auto wFullPath = charset::ToWide( fullPath.c_str() );
+-        if ( _wmkdir( wFullPath.get() ) != 0 )
++        if ( !wFullPath || _wmkdir( wFullPath.get() ) != 0 )
+ #else
+         if ( ::mkdir( fullPath.c_str(), S_IRWXU ) != 0 )
+ #endif
+@@ -203,6 +205,8 @@ bool rmdir( std::string path )
+     WIN32_FIND_DATA f;
+     auto pattern = path + '*';
+     auto wpattern = charset::ToWide( pattern.c_str() );
++    if ( !wpattern )
++        return false;
+     auto h = FindFirstFile( wpattern.get(), &f );
+     if ( h == INVALID_HANDLE_VALUE )
+     {
+@@ -231,6 +235,8 @@ bool rmdir( std::string path )
+         }
+     } while ( FindNextFile( h, &f ) != 0 );
+     auto wPath = charset::ToWide( path.c_str() );
++    if ( !wPath )
++        return false;
+     auto res = _wrmdir( wPath.get() );
+     if ( res == 0 )
+         return true;
+-- 
+2.45.0.windows.1
+


=====================================
contrib/src/medialibrary/rules.mak
=====================================
@@ -16,6 +16,12 @@ $(TARBALLS)/medialibrary-$(MEDIALIBRARY_VERSION).tar.bz2:
 medialibrary: medialibrary-$(MEDIALIBRARY_VERSION).tar.bz2 .sum-medialibrary
 	$(UNPACK)
 	$(APPLY) $(SRC)/medialibrary/Fix-CacheWorker.patch
+	$(APPLY) $(SRC)/medialibrary/0002-win32-DeviceLister-don-t-use-wchar_t-string-if-they-.patch
+	$(APPLY) $(SRC)/medialibrary/0003-utils-Directory-don-t-use-wchar_t-string-if-they-are.patch
+	$(APPLY) $(SRC)/medialibrary/0004-test-common-don-t-use-wchar_t-string-if-they-are-NUL.patch
+	$(APPLY) $(SRC)/medialibrary/0005-LockFile-don-t-use-char-string-if-they-are-NULL.patch
+	$(APPLY) $(SRC)/medialibrary/0006-fs-Directory-don-t-use-char-string-if-they-are-NULL.patch
+	$(APPLY) $(SRC)/medialibrary/0007-utils-Directory-don-t-use-char-string-if-they-are-NU.patch
 	$(MOVE)
 
 .medialibrary: medialibrary crossfile.meson



View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/d360da6bf8bf2dfceeab0da319d4cd9f070ec4ff

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/commit/d360da6bf8bf2dfceeab0da319d4cd9f070ec4ff
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