From 2f43afedd414ac0525c7c562841358ed10e972fe Mon Sep 17 00:00:00 2001 From: qianlifeng Date: Sat, 12 Jul 2025 23:40:04 +0800 Subject: [PATCH] refactor(windows): improve Unicode handling in `queryVersionString` * Added a check for zero length in `puLen` to prevent unnecessary slice creation. * Adjusted the slice length for UTF16 conversion to match the actual length needed. * Enhanced clarity and safety in handling UTF16 strings. --- wox.core/plugin/system/app/app_windows.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/wox.core/plugin/system/app/app_windows.go b/wox.core/plugin/system/app/app_windows.go index 982a7ee1..7264fae0 100644 --- a/wox.core/plugin/system/app/app_windows.go +++ b/wox.core/plugin/system/app/app_windows.go @@ -41,6 +41,7 @@ var ( // Windows constants for icon extraction const ( SHGFI_ICON = 0x000000100 + SHGFI_DISPLAYNAME = 0x000000200 SHGFI_LARGEICON = 0x000000000 SHGFI_SMALLICON = 0x000000001 SHGFI_SYSICONINDEX = 0x000004000 @@ -480,8 +481,17 @@ func (a *WindowsRetriever) queryVersionString(ctx context.Context, buffer []byte } // Convert UTF16 string to Go string - utf16Slice := (*[256]uint16)(unsafe.Pointer(lpBuffer))[:puLen/2] - return syscall.UTF16ToString(utf16Slice) + // puLen is already the number of UTF16 characters (not bytes) + utf16Length := puLen + if utf16Length == 0 { + return "" + } + + // Create a slice with the exact length needed + utf16Slice := (*[1024]uint16)(unsafe.Pointer(lpBuffer))[:utf16Length] + result := syscall.UTF16ToString(utf16Slice) + + return result } func (a *WindowsRetriever) GetExtraApps(ctx context.Context) ([]appInfo, error) {