Fix #111379: Allow Win32 Volume Names to Contain Characters > U+FFFF

When processing volume names for the File Browser sidebar lists we are
properly handling Windows "wide" characters (UTF-16) as long as they
are single wide characters, so below U+FFFF. For characters above this
value we get a pair of UTF-16, and end up trying to convert each to
UTF-8 as separate UTF-32 values. The result is blank output and a
console error that "surrogates not allowed." This PR just does this
conversion correctly using utfconv.

Pull Request: https://projects.blender.org/blender/blender/pulls/131763
This commit is contained in:
Harley Acheson 2024-12-12 00:49:33 +01:00 committed by Harley Acheson
parent 3bbf546d28
commit fe6609c4eb
3 changed files with 10 additions and 6 deletions

View file

@ -3,7 +3,7 @@
# SPDX-License-Identifier: GPL-2.0-or-later
set(INC
.
PUBLIC .
)
set(INC_SYS
@ -30,3 +30,4 @@ if(WIN32)
endif()
blender_add_lib(bf_intern_utfconv "${SRC}" "${INC}" "${INC_SYS}" "${LIB}")
add_library(bf::intern::utfconv ALIAS bf_intern_utfconv)

View file

@ -55,6 +55,9 @@ set(LIB
if(WIN32)
add_definitions(-DNOMINMAX)
list(APPEND LIB
PRIVATE bf::intern::utfconv
)
endif()
if(WITH_HEADLESS)

View file

@ -27,7 +27,7 @@
#include "ED_fileselect.hh"
#ifdef WIN32
# include "BLI_string_utf8.h" /* For `BLI_strncpy_wchar_as_utf8`. */
# include "utfconv.hh"
/* Need to include windows.h so _WIN32_IE is defined. */
# include <windows.h>
@ -211,7 +211,7 @@ static void fsmenu_add_windows_quick_access(FSMenu *fsmenu,
}
char utf_path[FILE_MAXDIR];
BLI_strncpy_wchar_as_utf8(utf_path, path, FILE_MAXDIR);
conv_utf_16_to_8(path, utf_path, FILE_MAXDIR);
/* Skip library folders since they are not currently supported. */
if (!BLI_strcasestr(utf_path, ".library-ms")) {
@ -232,7 +232,7 @@ static void fsmenu_add_windows_folder(FSMenu *fsmenu,
LPWSTR pPath;
char line[FILE_MAXDIR];
if (SHGetKnownFolderPath(rfid, 0, nullptr, &pPath) == S_OK) {
BLI_strncpy_wchar_as_utf8(line, pPath, FILE_MAXDIR);
conv_utf_16_to_8(pPath, line, FILE_MAXDIR);
fsmenu_insert_entry(fsmenu, category, line, name, icon, flag);
}
CoTaskMemFree(pPath);
@ -262,7 +262,7 @@ void fsmenu_read_system(FSMenu *fsmenu, int read_bookmarks)
/* Skip over floppy disks A & B. */
if (i > 1) {
/* Friendly volume descriptions without using SHGetFileInfoW (#85689). */
BLI_strncpy_wchar_from_utf8(wline, tmps, 4);
conv_utf_8_to_16(tmps, wline, 4);
IShellFolder *desktop;
if (SHGetDesktopFolder(&desktop) == S_OK) {
PIDLIST_RELATIVE volume;
@ -274,7 +274,7 @@ void fsmenu_read_system(FSMenu *fsmenu, int read_bookmarks)
if (desktop->GetDisplayNameOf(volume, SHGDN_FORADDRESSBAR, &volume_name) == S_OK) {
wchar_t *volume_name_wchar;
if (StrRetToStrW(&volume_name, volume, &volume_name_wchar) == S_OK) {
BLI_strncpy_wchar_as_utf8(line, volume_name_wchar, FILE_MAXDIR);
conv_utf_16_to_8(volume_name_wchar, line, FILE_MAXDIR);
name = line;
CoTaskMemFree(volume_name_wchar);
}